linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Unsigned off_t?
@ 2005-07-25  8:47 Holger Kiehl
  2005-07-25  8:53 ` Jeff Woods
  2005-07-26  5:24 ` Glynn Clements
  0 siblings, 2 replies; 12+ messages in thread
From: Holger Kiehl @ 2005-07-25  8:47 UTC (permalink / raw)
  To: linux-c-programming

Hello

I would like to have an unsigned off_t, what is the best and portbale way
to define this? Currently I use the following code:

    #if SIZEOF_OFF_T == 4
    typedef unsigned long       u_off_t;
    #else
    typedef unsigned long long  u_off_t;
    #endif

SIZEOF_OFF_T is returned from the gnu autoconfig tools.

Is this the correct way of doing this? Or is there some better more portable
way?

Thanks,
Holger
-- 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Unsigned off_t?
  2005-07-25  8:47 Unsigned off_t? Holger Kiehl
@ 2005-07-25  8:53 ` Jeff Woods
  2005-07-25  9:00   ` Holger Kiehl
  2005-07-26  5:24 ` Glynn Clements
  1 sibling, 1 reply; 12+ messages in thread
From: Jeff Woods @ 2005-07-25  8:53 UTC (permalink / raw)
  To: Holger Kiehl; +Cc: linux-c-programming

At 7/25/2005 08:47 +0000, Holger Kiehl wrote:
>I would like to have an unsigned off_t, what is the best and 
>portable way to define this? Currently I use the following code:
>
>    #if SIZEOF_OFF_T == 4
>    typedef unsigned long       u_off_t;
>    #else
>    typedef unsigned long long  u_off_t;
>    #endif
>
>SIZEOF_OFF_T is returned from the gnu autoconfig tools.
>
>Is this the correct way of doing this? Or is there some better more 
>portable way?

Does the following do what you want?

         typedef unsigned off_t u_off_t;

--
Jeff Woods <kazrak+kernel@cesmail.net> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Unsigned off_t?
  2005-07-25  8:53 ` Jeff Woods
@ 2005-07-25  9:00   ` Holger Kiehl
  0 siblings, 0 replies; 12+ messages in thread
From: Holger Kiehl @ 2005-07-25  9:00 UTC (permalink / raw)
  To: Jeff Woods; +Cc: linux-c-programming

On Mon, 25 Jul 2005, Jeff Woods wrote:

> At 7/25/2005 08:47 +0000, Holger Kiehl wrote:
>> I would like to have an unsigned off_t, what is the best and portable way 
>> to define this? Currently I use the following code:
>> 
>>    #if SIZEOF_OFF_T == 4
>>    typedef unsigned long       u_off_t;
>>    #else
>>    typedef unsigned long long  u_off_t;
>>    #endif
>> 
>> SIZEOF_OFF_T is returned from the gnu autoconfig tools.
>> 
>> Is this the correct way of doing this? Or is there some better more 
>> portable way?
>
> Does the following do what you want?
>
>        typedef unsigned off_t u_off_t;
>
No, this is what I tried first but does not compile. Try the following code:

    #include <stdio.h>
    #include <sys/types.h>

    typedef unsigned off_t u_off_t;

    int
    main(void)
    {
       u_off_t a;

       return 0;
    }

Thanks,
Holger


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Unsigned off_t?
  2005-07-25  8:47 Unsigned off_t? Holger Kiehl
  2005-07-25  8:53 ` Jeff Woods
@ 2005-07-26  5:24 ` Glynn Clements
  2005-07-26  7:38   ` Holger Kiehl
  1 sibling, 1 reply; 12+ messages in thread
From: Glynn Clements @ 2005-07-26  5:24 UTC (permalink / raw)
  To: Holger Kiehl; +Cc: linux-c-programming


Holger Kiehl wrote:

> I would like to have an unsigned off_t, what is the best and portbale way
> to define this? Currently I use the following code:
> 
>     #if SIZEOF_OFF_T == 4
>     typedef unsigned long       u_off_t;
>     #else
>     typedef unsigned long long  u_off_t;
>     #endif
> 
> SIZEOF_OFF_T is returned from the gnu autoconfig tools.
> 
> Is this the correct way of doing this?

There isn't any "correct" way of doing it.

> Or is there some better more portable way?

Using the types from stdint.h (uint32_t, uint64_t etc) would be more
portable than making assumptions about the sizes of "long", "long long"
etc. Alternatively:

	#if SIZEOF_OFF_T == SIZEOF_INT
	typedef unsigned int off_t
	#elif SIZEOF_OFF_T == SIZEOF_LONG
	typedef unsigned long off_t
	#elif SIZEOF_OFF_T == SIZEOF_LONG_LONG
	typedef unsigned long long off_t
	#endif

Out of curiosity, why do you want an unsigned off_t anyhow?

-- 
Glynn Clements <glynn@gclements.plus.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Unsigned off_t?
  2005-07-26  5:24 ` Glynn Clements
@ 2005-07-26  7:38   ` Holger Kiehl
  2005-07-26 16:53     ` superblock & inode's Nanakos Chrysostomos
  2005-07-27  7:23     ` Unsigned off_t? Glynn Clements
  0 siblings, 2 replies; 12+ messages in thread
From: Holger Kiehl @ 2005-07-26  7:38 UTC (permalink / raw)
  To: Glynn Clements; +Cc: linux-c-programming

On Tue, 26 Jul 2005, Glynn Clements wrote:

>
> Holger Kiehl wrote:
>
>> I would like to have an unsigned off_t, what is the best and portbale way
>> to define this? Currently I use the following code:
>>
>>     #if SIZEOF_OFF_T == 4
>>     typedef unsigned long       u_off_t;
>>     #else
>>     typedef unsigned long long  u_off_t;
>>     #endif
>>
>> SIZEOF_OFF_T is returned from the gnu autoconfig tools.
>>
>> Is this the correct way of doing this?
>
> There isn't any "correct" way of doing it.
>
>> Or is there some better more portable way?
>
> Using the types from stdint.h (uint32_t, uint64_t etc) would be more
> portable than making assumptions about the sizes of "long", "long long"
> etc.
>
So a solution with C99 and stdint.h could look as follows:

         #ifdef HAVE_STDINT_H
         # if SIZEOF_OFF_T == 4
         typedef uint32_t u_off_t;
         # else
         typedef uint64_t u_off_t;
         # endif
         #else
         # if SIZEOF_OFF_T == 4
         typedef unsigned long u_off_t;
         # else
         typedef unsigned long long u_off_t;
         # endif
         #endif

The problem I have with this is how do I use this with printf() or fprintf()?
What do I use: %u, %lu or %llu? Does C99 provide a solution here?

> Alternatively:
>
> 	#if SIZEOF_OFF_T == SIZEOF_INT
> 	typedef unsigned int off_t
> 	#elif SIZEOF_OFF_T == SIZEOF_LONG
> 	typedef unsigned long off_t
> 	#elif SIZEOF_OFF_T == SIZEOF_LONG_LONG
> 	typedef unsigned long long off_t
> 	#endif
>
Same problem here as well, how to use this with printf()?

Besides, what do I use for uint64_t in printf()?

> Out of curiosity, why do you want an unsigned off_t anyhow?
>
I use it to store the number of bytes I have send to a certain host.
If this is unsigned there is no need to worry about an overflow and I can
always just add each file size transmitted. Just when I want to calculate
the transfer rate I need to watch out for an overflow.

Thanks,
Holger


^ permalink raw reply	[flat|nested] 12+ messages in thread

* superblock & inode's
  2005-07-26  7:38   ` Holger Kiehl
@ 2005-07-26 16:53     ` Nanakos Chrysostomos
  2005-07-26 16:59       ` Robert P. J. Day
                         ` (2 more replies)
  2005-07-27  7:23     ` Unsigned off_t? Glynn Clements
  1 sibling, 3 replies; 12+ messages in thread
From: Nanakos Chrysostomos @ 2005-07-26 16:53 UTC (permalink / raw)
  To: linux-c-programming

Hi all,
i want to read the superblock & inode for a block device.
I dont want to use readdir to get the inode and dir name.I want to do it
like the skeleton below,can someone help me??


#include <sys/types.h>
#include <stdio.h>

int main()
{

struct what_struct d; /* What struct to use for inode*/
struct what_struct_sb sb; /*What struct to use for superblock */
int fd;

fd=open("/dev/hda1",0);
lseek(fd,4096L,0); /* Is this the first inode?? Where is the next one?*/
/*Where is the superblock allocated in the disk */
read(fd,&d,sizeof(d));
/*Retrieve information now ....*/

return 0;
}


Can i have a working example please???
Thanks in advance.





^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: superblock & inode's
  2005-07-26 16:53     ` superblock & inode's Nanakos Chrysostomos
@ 2005-07-26 16:59       ` Robert P. J. Day
  2005-07-27  5:21       ` sumit kalra
  2005-07-27  7:24       ` Glynn Clements
  2 siblings, 0 replies; 12+ messages in thread
From: Robert P. J. Day @ 2005-07-26 16:59 UTC (permalink / raw)
  To: Nanakos Chrysostomos; +Cc: linux-c-programming

On Tue, 26 Jul 2005, Nanakos Chrysostomos wrote:

> Hi all,
> i want to read the superblock & inode for a block device.
> I dont want to use readdir to get the inode and dir name.I want to do it
> like the skeleton below,can someone help me??
>
>
> #include <sys/types.h>
> #include <stdio.h>
>
> int main()
> {
>
> struct what_struct d; /* What struct to use for inode*/
> struct what_struct_sb sb; /*What struct to use for superblock */
> int fd;
>
> fd=open("/dev/hda1",0);
> lseek(fd,4096L,0); /* Is this the first inode?? Where is the next one?*/
> /*Where is the superblock allocated in the disk */
> read(fd,&d,sizeof(d));
> /*Retrieve information now ....*/
>
> return 0;
> }

your best bet is to get a copy of the kernel source and check out the
directory fs/ext3, particularly the source files super.c and inode.c.

rday

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: superblock & inode's
  2005-07-26 16:53     ` superblock & inode's Nanakos Chrysostomos
  2005-07-26 16:59       ` Robert P. J. Day
@ 2005-07-27  5:21       ` sumit kalra
  2005-07-27  7:24       ` Glynn Clements
  2 siblings, 0 replies; 12+ messages in thread
From: sumit kalra @ 2005-07-27  5:21 UTC (permalink / raw)
  To: nanakos, linux-c-programming

Hi,

> lseek(fd,4096L,0); /* Is this the first inode??
> Where is the next one?*/
> /*Where is the superblock allocated in the disk */
The location of the superblock and the inodes
(including the first one) depend on the kind of
filesystem you have on the disk. Some filesystems have
the superblock immediately after the boot block
(ext2/3) and others may not have it at all (NTFS).

Also the structure of on-disk superblocks and inodes
vary with each filesystem.

If you know which filesystem your disk has then you
can read in the relevent blocks. Then you can look at
the filesystem code and find out what data structure
defines the superblock and typecast the block of data
accordingly.

I am not sure if there is a better way to do it but
this is all that came to my mind :-) 
Hope it helps,
Sumit Kalra

--- Nanakos Chrysostomos <nanakos@wired-net.gr> wrote:

> Hi all,
> i want to read the superblock & inode for a block
> device.
> I dont want to use readdir to get the inode and dir
> name.I want to do it
> like the skeleton below,can someone help me??
> 
> 
> #include <sys/types.h>
> #include <stdio.h>
> 
> int main()
> {
> 
> struct what_struct d; /* What struct to use for
> inode*/
> struct what_struct_sb sb; /*What struct to use for
> superblock */
> int fd;
> 
> fd=open("/dev/hda1",0);
> lseek(fd,4096L,0); /* Is this the first inode??
> Where is the next one?*/
> /*Where is the superblock allocated in the disk */
> read(fd,&d,sizeof(d));
> /*Retrieve information now ....*/
> 
> return 0;
> }
> 
> 
> Can i have a working example please???
> Thanks in advance.
> 
> 
> 
> 
> -
> To unsubscribe from this list: send the line
> "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at 
> http://vger.kernel.org/majordomo-info.html
> 



	
	
		
___________________________________________________________ 
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Unsigned off_t?
  2005-07-26  7:38   ` Holger Kiehl
  2005-07-26 16:53     ` superblock & inode's Nanakos Chrysostomos
@ 2005-07-27  7:23     ` Glynn Clements
  2005-07-27 20:09       ` Holger Kiehl
  1 sibling, 1 reply; 12+ messages in thread
From: Glynn Clements @ 2005-07-27  7:23 UTC (permalink / raw)
  To: Holger Kiehl; +Cc: linux-c-programming


Holger Kiehl wrote:

> The problem I have with this is how do I use this with printf() or fprintf()?
> What do I use: %u, %lu or %llu? Does C99 provide a solution here?

       7.8  Format conversion of integer types <inttypes.h>

       [#1] The header <inttypes.h> includes the header  <stdint.h>
       and extends it with additional facilities provided by hosted
       implementations.

       [#2] It  declares  four  functions  for  converting  numeric
       character  strings  to greatest-width integers and, for each
       type declared in <stdint.h>, it defines corresponding macros
       for   conversion  specifiers  for  use  with  the  formatted
       input/output functions.169)

       Forward references:  integer types <stdint.h> (7.18).

       7.8.1  Macros for format specifiers

       [#1] Each of the following object-like macros170) expands to
       a   character   string   literal   containing  a  conversion
       specifier, possibly modified by a length modifier,  suitable
       for   use   within   the  format  argument  of  a  formatted
       input/output  function  when  converting  the  corresponding
       integer  type.   These  macro names have the general form of
       PRI (character string literals for the  fprintf  family)  or
       SCN (character string literals for the fscanf  family),171)
       followed  by  the  conversion  specifier, followed by a name
       corresponding  to  a  similar  type  name  in  7.18.1.   For
       example,  PRIdFAST32 can be used in a format string to print
       the value of an integer of type int_fast32_t.

       [#2] The fprintf macros for signed integers are:

           PRId8          PRId16         PRId32         PRId64
           PRIdLEAST8     PRIdLEAST16    PRIdLEAST32    PRIdLEAST64
           PRIdFAST8      PRIdFAST16     PRIdFAST32     PRIdFAST64
           PRIdMAX        PRIdPTR

           PRIi8          PRIi16         PRIi32         PRIi64
           PRIiLEAST8     PRIiLEAST16    PRIiLEAST32    PRIiLEAST64
           PRIiFAST8      PRIiFAST16     PRIiFAST32     PRIiFAST64
           PRIiMAX        PRIiPTR

       [#3] The fprintf macros for unsigned integers are:

           PRIo8          PRIo16         PRIo32         PRIo64
           PRIoLEAST8     PRIoLEAST16    PRIoLEAST32    PRIoLEAST64
           PRIoFAST8      PRIoFAST16     PRIoFAST32     PRIoFAST64
           PRIoMAX        PRIoPTR

           PRIu8          PRIu16         PRIu32         PRIu64
           PRIuLEAST8     PRIuLEAST16    PRIuLEAST32    PRIuLEAST64
           PRIuFAST8      PRIuFAST16     PRIuFAST32     PRIuFAST64
           PRIuMAX        PRIuPTR

           PRIx8          PRIx16         PRIx32         PRIx64
           PRIxLEAST8     PRIxLEAST16    PRIxLEAST32    PRIxLEAST64
           PRIxFAST8      PRIxFAST16     PRIxFAST32     PRIxFAST64
           PRIxMAX        PRIxPTR

           PRIX8          PRIX16         PRIX32         PRIX64
           PRIXLEAST8     PRIXLEAST16    PRIXLEAST32    PRIXLEAST64
           PRIXFAST8      PRIXFAST16     PRIXFAST32     PRIXFAST64
           PRIXMAX        PRIXPTR

> Besides, what do I use for uint64_t in printf()?

The PRIu64 macro.

> > Out of curiosity, why do you want an unsigned off_t anyhow?
> 
> I use it to store the number of bytes I have send to a certain host.
> If this is unsigned there is no need to worry about an overflow and I can
> always just add each file size transmitted. Just when I want to calculate
> the transfer rate I need to watch out for an overflow.

Why not just use "long long" or "int64_t"?

If you're sending multiple files, I can't see any reason why the total
amount of data sent would depend upon sizeof(off_t).

If you're always using a 64-bit type, there isn't any reason to use
unsigned. I'm fairly certain that you aren't going to be sending more
than 2^63 bytes; even at 1Gbit/sec, that would take ~2000 years.

If you're using a 32-bit type, overflow is a realistic possibility
regardless of whether you use signed or unsigned.

-- 
Glynn Clements <glynn@gclements.plus.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: superblock & inode's
  2005-07-26 16:53     ` superblock & inode's Nanakos Chrysostomos
  2005-07-26 16:59       ` Robert P. J. Day
  2005-07-27  5:21       ` sumit kalra
@ 2005-07-27  7:24       ` Glynn Clements
  2005-07-27 18:53         ` Nanakos Chrysostomos
  2 siblings, 1 reply; 12+ messages in thread
From: Glynn Clements @ 2005-07-27  7:24 UTC (permalink / raw)
  To: nanakos; +Cc: linux-c-programming


Nanakos Chrysostomos wrote:

> i want to read the superblock & inode for a block device.
> I dont want to use readdir to get the inode and dir name.I want to do it
> like the skeleton below,can someone help me??
> 
> 
> #include <sys/types.h>
> #include <stdio.h>
> 
> int main()
> {
> 
> struct what_struct d; /* What struct to use for inode*/
> struct what_struct_sb sb; /*What struct to use for superblock */
> int fd;
> 
> fd=open("/dev/hda1",0);
> lseek(fd,4096L,0); /* Is this the first inode?? Where is the next one?*/
> /*Where is the superblock allocated in the disk */

The layout of a filesystem depends entirely upon the filesystem type
(ext2, vfat etc).

You should look at the source code for filesystem specific tools (e.g.
e2fsprogs, dosfstools etc) for example code.

-- 
Glynn Clements <glynn@gclements.plus.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: superblock & inode's
  2005-07-27  7:24       ` Glynn Clements
@ 2005-07-27 18:53         ` Nanakos Chrysostomos
  0 siblings, 0 replies; 12+ messages in thread
From: Nanakos Chrysostomos @ 2005-07-27 18:53 UTC (permalink / raw)
  To: Glynn Clements; +Cc: nanakos, linux-c-programming

I looked the sources and the programs use the libext2fs library.I found it
in the sources but it is loss of time reading it just to understand and
retrieve some simple things.So i finally did this below,but i am stack
only in one thing.How to parse the information for a data block that
contains the info for the dir's & files , e.g / directory.Please check the
code below.
The data block allocates 8 blocks ( in my machine 4096 bytes ),the data
are struct ext2_dir_entry_2 structures.But the name lenght isn't always
the same so i cant parse it just knowing the sizeof the structure.Maybe an
iteration with llseek will help.Can someone help me with this algorithm???
Have you got sth to propose????


#include <ext2fs/ext2_fs.h>
#include <fcntl.h>
#include <math.h>


int main()
{
	int fd,of;
	char buf[8*4096];
	int count=0;
	struct ext2_super_block s;
	struct ext2_group_desc g;
	struct ext2_inode i;
	struct ext2_dir_entry_2 dir;
	int block_size,is=0,dir_entry_size;

	fd = open("/dev/hdb2",O_RDONLY);

	lseek(fd,1024L,0);

	read(fd,&s,sizeof(s));

	printf("%d inodes (%d free)\n",s.s_inodes_count,s.s_free_inodes_count);
	printf("%d blocks (%d free)\n",s.s_blocks_count,s.s_free_blocks_count);


	block_size = s.s_log_block_size;

	block_size = pow(2,block_size)*1024;

	printf("Block size: %d\n",block_size);

	printf("Volume name: %s\n",s.s_volume_name);
	printf("Inode size : %d\n",s.s_inode_size);


	lseek(fd,4096L,0);

	read(fd,&g,sizeof(g));

	printf("Inodes Table Block:%d\n",g.bg_inode_table);


	lseek(fd,4*4096L+128L,0); /*inode 2 */

	read(fd,&i,sizeof(i));


	printf("Pointer to data block:%d\n",i.i_block[0]);
	printf("Data blocks occupied:%d\n",i.i_blocks);


	dir_entry_size = sizeof(dir);

	printf("%d\n",dir_entry_size);

	/* Read data block and retrieve directory & file information */
	lseek(fd,i.i_block[0]*4096L,0);
	is += read(fd,&dir,12);
	printf("name:%s inode:%d name_len:%d rec_len:%d
file_type:%d\n",dir.name,dir.inode,dir.name_len,dir.rec_len,dir.file_type);


	is += read(fd,&dir,19);
	printf("name:%s inode:%d name_len:%d rec_len:%d
file_type:%d\n",dir.name,dir.inode,dir.name_len,dir.rec_len,dir.file_type);

	is += read(fd,&dir,12);
	printf("name:%s inode:%d name_len:%d rec_len:%d
file_type:%d\n",dir.name,dir.inode,dir.name_len,dir.rec_len,dir.file_type);

	close(fd);

	return 0;
}


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Unsigned off_t?
  2005-07-27  7:23     ` Unsigned off_t? Glynn Clements
@ 2005-07-27 20:09       ` Holger Kiehl
  0 siblings, 0 replies; 12+ messages in thread
From: Holger Kiehl @ 2005-07-27 20:09 UTC (permalink / raw)
  To: Glynn Clements; +Cc: linux-c-programming

On Wed, 27 Jul 2005, Glynn Clements wrote:

>
> Holger Kiehl wrote:
>
>> The problem I have with this is how do I use this with printf() or fprintf()?
>> What do I use: %u, %lu or %llu? Does C99 provide a solution here?
>
>       7.8  Format conversion of integer types <inttypes.h>
>
>       [#1] The header <inttypes.h> includes the header  <stdint.h>
>       and extends it with additional facilities provided by hosted
>       implementations.
>
>       [#2] It  declares  four  functions  for  converting  numeric
>       character  strings  to greatest-width integers and, for each
>       type declared in <stdint.h>, it defines corresponding macros
>       for   conversion  specifiers  for  use  with  the  formatted
>       input/output functions.169)
>
>       Forward references:  integer types <stdint.h> (7.18).
>
>       7.8.1  Macros for format specifiers
>
>       [#1] Each of the following object-like macros170) expands to
>       a   character   string   literal   containing  a  conversion
>       specifier, possibly modified by a length modifier,  suitable
>       for   use   within   the  format  argument  of  a  formatted
>       input/output  function  when  converting  the  corresponding
>       integer  type.   These  macro names have the general form of
>       PRI (character string literals for the  fprintf  family)  or
>       SCN (character string literals for the fscanf  family),171)
>       followed  by  the  conversion  specifier, followed by a name
>       corresponding  to  a  similar  type  name  in  7.18.1.   For
>       example,  PRIdFAST32 can be used in a format string to print
>       the value of an integer of type int_fast32_t.
>
>       [#2] The fprintf macros for signed integers are:
>
>           PRId8          PRId16         PRId32         PRId64
>           PRIdLEAST8     PRIdLEAST16    PRIdLEAST32    PRIdLEAST64
>           PRIdFAST8      PRIdFAST16     PRIdFAST32     PRIdFAST64
>           PRIdMAX        PRIdPTR
>
>           PRIi8          PRIi16         PRIi32         PRIi64
>           PRIiLEAST8     PRIiLEAST16    PRIiLEAST32    PRIiLEAST64
>           PRIiFAST8      PRIiFAST16     PRIiFAST32     PRIiFAST64
>           PRIiMAX        PRIiPTR
>
>       [#3] The fprintf macros for unsigned integers are:
>
>           PRIo8          PRIo16         PRIo32         PRIo64
>           PRIoLEAST8     PRIoLEAST16    PRIoLEAST32    PRIoLEAST64
>           PRIoFAST8      PRIoFAST16     PRIoFAST32     PRIoFAST64
>           PRIoMAX        PRIoPTR
>
>           PRIu8          PRIu16         PRIu32         PRIu64
>           PRIuLEAST8     PRIuLEAST16    PRIuLEAST32    PRIuLEAST64
>           PRIuFAST8      PRIuFAST16     PRIuFAST32     PRIuFAST64
>           PRIuMAX        PRIuPTR
>
>           PRIx8          PRIx16         PRIx32         PRIx64
>           PRIxLEAST8     PRIxLEAST16    PRIxLEAST32    PRIxLEAST64
>           PRIxFAST8      PRIxFAST16     PRIxFAST32     PRIxFAST64
>           PRIxMAX        PRIxPTR
>
>           PRIX8          PRIX16         PRIX32         PRIX64
>           PRIXLEAST8     PRIXLEAST16    PRIXLEAST32    PRIXLEAST64
>           PRIXFAST8      PRIXFAST16     PRIXFAST32     PRIXFAST64
>           PRIXMAX        PRIXPTR
>
>> Besides, what do I use for uint64_t in printf()?
>
> The PRIu64 macro.
>
Thanks for the information!

>>> Out of curiosity, why do you want an unsigned off_t anyhow?
>>
>> I use it to store the number of bytes I have send to a certain host.
>> If this is unsigned there is no need to worry about an overflow and I can
>> always just add each file size transmitted. Just when I want to calculate
>> the transfer rate I need to watch out for an overflow.
>
> Why not just use "long long" or "int64_t"?
>
> If you're sending multiple files, I can't see any reason why the total
> amount of data sent would depend upon sizeof(off_t).
>
You are right, that is a much better solution. Thanks!

> If you're always using a 64-bit type, there isn't any reason to use
> unsigned. I'm fairly certain that you aren't going to be sending more
> than 2^63 bytes; even at 1Gbit/sec, that would take ~2000 years.
>
> If you're using a 32-bit type, overflow is a realistic possibility
> regardless of whether you use signed or unsigned.
>
Yes this is what happened to my surprise. On one platform off_t is only
32-bit and overflowed very quickly.

Holger


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2005-07-27 20:09 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-25  8:47 Unsigned off_t? Holger Kiehl
2005-07-25  8:53 ` Jeff Woods
2005-07-25  9:00   ` Holger Kiehl
2005-07-26  5:24 ` Glynn Clements
2005-07-26  7:38   ` Holger Kiehl
2005-07-26 16:53     ` superblock & inode's Nanakos Chrysostomos
2005-07-26 16:59       ` Robert P. J. Day
2005-07-27  5:21       ` sumit kalra
2005-07-27  7:24       ` Glynn Clements
2005-07-27 18:53         ` Nanakos Chrysostomos
2005-07-27  7:23     ` Unsigned off_t? Glynn Clements
2005-07-27 20:09       ` Holger Kiehl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).