autoconf
[Top][All Lists]
Advanced

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

Portability of fopen (foo, "wb") (Was: bug in AC_COMPUTE_INT)


From: Akim Demaille
Subject: Portability of fopen (foo, "wb") (Was: bug in AC_COMPUTE_INT)
Date: 16 Nov 2000 14:55:44 +0100
User-agent: Gnus/5.0807 (Gnus v5.8.7) XEmacs/21.1 (Channel Islands)

| On Thu, Nov 16, 2000 at 12:51:05PM +0100, Akim Demaille wrote:
| : 
| : | -[FILE *f = fopen ("conftestval", "w");
| : | +[FILE *f = fopen ("conftestval", "wb");
| : 
| : Portable?
| 
| Not really my cup of tea, but (from fopen(3) on Linux):
| 
| # The mode string can also include the letter ``b'' either as a third
| # character or as a charĀ­ acter between the characters in any of the
| # two-character strings described above.  This is strictly for
| # compatibility with ANSI C3.159-1989 (``ANSI C'') and has no effect;
| # the ``b'' is ignored.

Does anybody know whether using fopen (foo, "wb") is portable?  Gary
uses a test for this, but I don't know if it's really needed.  A grep
on the packages I have at hand show this:

gawk/gawk-3.1.84/pc/popen.c:  if ( ((fp = fopen(p, "wb")) == NULL) || 
(fwrite(command, 1, i, fp) < i)
gawk/pc/popen.c:  if ( ((fp = fopen(p, "wb")) == NULL) || (fwrite(command, 1, 
i, fp) < i)

This seems to be for pc only, so no information.

libc/gmon/bb_exit_func.c:  fp = fopen (OUT_NAME, "wb");
libc/nis/nis_file.c:  out = fopen (cold_start_file, "wb");
libc/nis/nis_file.c:  out = fopen (name, "wb");
libc/timezone/zic.c:    if ((fp = fopen(fullname, "wb")) == NULL) {
libc/timezone/zic.c:            if ((fp = fopen(fullname, "wb")) == NULL) {

Since the libc comes with its own fopen, we learn nothing.

libppd-0.4/pstops.c:    
if((temp=fopen(cupsTempFile(tempfile,sizeof(tempfile)),"wb+"))==NULL){

I'm not sure this lib is really portable.

Jim has this in the textutils:

tu/src/md5sum.c:      fp = fopen (filename, OPENOPTS (binary));

with

/* Most systems do not distinguish between external and internal
   text representations.  */
/* FIXME: This begs for an autoconf test.  */
#if O_BINARY
# define OPENOPTS(BINARY) ((BINARY) != 0 ? TEXT1TO1 : TEXTCNVT)
# define TEXT1TO1 "rb"
# define TEXTCNVT "r"
#else
# if defined VMS
#  define OPENOPTS(BINARY) ((BINARY) != 0 ? TEXT1TO1 : TEXTCNVT)
#  define TEXT1TO1 "rb", "ctx=stm"
#  define TEXTCNVT "r", "ctx=stm"
# else
#  if UNIX || __UNIX__ || unix || __unix__ || _POSIX_VERSION
#   define OPENOPTS(BINARY) "r"
#  else
    /* The following line is intended to evoke an error.
       Using #error is not portable enough.  */
    "Cannot determine system type."
#  endif
# endif
#endif



reply via email to

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