autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question regarding sscanf() vs. off_t and similar


From: Philipp Marek
Subject: Question regarding sscanf() vs. off_t and similar
Date: Wed, 13 Sep 2006 21:05:30 +0200
User-agent: KMail/1.9.3

Hello everybody!

I'm currently on my way to get my project a bit more portable, and I'm 
currently stuck on a problem where I don't see an nice way to solve it.
Maybe autoconf has an easy answer, that's why I'm asking here.

(Please keep me CC:ed, I'm already on too many mailings lists :-)


The problem is that my code tries to use off_t, ino_t and similar, to be as 
compatible as possibly, and uses 64bit system calls.
That's no problem, as autoconf does this checks for me.

But where I'm stuck is that some systems have an 32bit off_t, others an 64bit 
off_t (and so on for other types, too), and I have problems writing my text 
files via sprintf() and friends.

If I'm doing 
        ino_t ino;
        char *name;
        sprintf("%Lu %s", ino, name);
that works fine for 64bit systems, but writes trash for sizeof(ino_t) == 4.

Is there an easy way to find the format strings (sprintf, printf, sscanf) for 
various system types, or something like that?

Or has somebody some already defined preprocessor magic to get this for some 
variable?
I'm thinking of something along the lines
        #define FORMAT(x)
          #if sizeof(x) == 4
            "%l"
          #else
            #if sizeof(x) == 8
              "%L"
            #else
              #error "Don't know size"
            #endif
          #endif

used like
        printf("hello" FORMAT(i) "\n", i);

Is there an easier/better way, something cleaner?


Thank you for all answers and ideas.


Regards,

Phil

-- 
Versioning your /etc, /home or even your whole installation?
             Try fsvs (fsvs.tigris.org)!




reply via email to

[Prev in Thread] Current Thread [Next in Thread]