Felix von Leitner <[EMAIL PROTECTED]> writes: > paste does not compile, because it tries to instantiate two FILE > variables just for the purpose of having values for FILE* to > recognize later.
Thanks for reporting this. I agree with Paul Jarc that the proposed fix wouldn't work in general, so I installed the (more elaborate) patch enclosed below instead. > There are other issues with coreutils: lib/fts_.h and lib/fts.c use "u_short". Thanks again. But I'm surprised you didn't run into other problems, e.g., with the "u_int". Can you please send a list of all the problems you ran into? Or was there something special about u_int on your host? Anyway, I installed the following patch to fix the problems you reported. 2004-09-02 Paul Eggert <[EMAIL PROTECTED]> Port to diet libc. Problem reported by Felix von Leitner in <http://lists.gnu.org/archive/html/bug-coreutils/2004-08/msg00171.html>. * lib/fts.c (fts_stat, fts_open, fts_read): Use "unsigned short int" rather than the unportable "u_short", and similarly for u_int. * lib/fts_.h (FTSENT): Likewise. * src/paste.c (dummy_closed, CLOSED, dummy_endlist, ENDLIST): Remove; it's not portable C to assume FILE is a complete type. (paste_parallel): Use null instead of ENDLIST, and an explicit boolean instead of CLOSED. Index: lib/fts.c =================================================================== RCS file: /home/eggert/coreutils/cu/lib/fts.c,v retrieving revision 1.19 diff -p -u -r1.19 fts.c --- lib/fts.c 11 Aug 2004 22:23:54 -0000 1.19 +++ lib/fts.c 2 Sep 2004 23:52:49 -0000 @@ -150,7 +150,8 @@ static size_t fts_maxarglen __P((char * static void fts_padjust __P((FTS *, FTSENT *)) internal_function; static bool fts_palloc __P((FTS *, size_t)) internal_function; static FTSENT *fts_sort __P((FTS *, FTSENT *, size_t)) internal_function; -static u_short fts_stat __P((FTS *, FTSENT *, bool)) internal_function; +static unsigned short int fts_stat __P((FTS *, FTSENT *, bool)) + internal_function; static int fts_safe_changedir __P((FTS *, FTSENT *, int, const char *)) internal_function; @@ -334,7 +335,7 @@ fts_open(argv, options, compar) } /* Allocate/initialize the stream */ - if ((sp = malloc((u_int)sizeof(FTS))) == NULL) + if ((sp = malloc(sizeof(FTS))) == NULL) return (NULL); memset(sp, 0, sizeof(FTS)); sp->fts_compar = (int (*) __P((const void *, const void *))) compar; @@ -539,7 +540,7 @@ fts_read(sp) register FTS *sp; { register FTSENT *p, *tmp; - register u_short instr; + register unsigned short int instr; register char *t; int saved_errno; @@ -1175,7 +1176,7 @@ fts_cross_check (FTS const *sp) } #endif -static u_short +static unsigned short int internal_function fts_stat(FTS *sp, register FTSENT *p, bool follow) { Index: lib/fts_.h =================================================================== RCS file: /home/eggert/coreutils/cu/lib/fts_.h,v retrieving revision 1.11 diff -p -u -r1.11 fts_.h --- lib/fts_.h 2 Aug 2004 19:41:35 -0000 1.11 +++ lib/fts_.h 2 Sep 2004 23:53:07 -0000 @@ -155,17 +155,17 @@ typedef struct _ftsent { # define FTS_SL 12 /* symbolic link */ # define FTS_SLNONE 13 /* symbolic link without target */ # define FTS_W 14 /* whiteout object */ - u_short fts_info; /* user flags for FTSENT structure */ + unsigned short int fts_info; /* user flags for FTSENT structure */ # define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */ # define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */ - u_short fts_flags; /* private flags for FTSENT structure */ + unsigned short int fts_flags; /* private flags for FTSENT structure */ # define FTS_AGAIN 1 /* read node again */ # define FTS_FOLLOW 2 /* follow symbolic link */ # define FTS_NOINSTR 3 /* no instructions */ # define FTS_SKIP 4 /* discard node */ - u_short fts_instr; /* fts_set() instructions */ + unsigned short int fts_instr; /* fts_set() instructions */ struct stat fts_statp[1]; /* stat(2) information */ char fts_name[1]; /* file name */ Index: src/paste.c =================================================================== RCS file: /home/eggert/coreutils/cu/src/paste.c,v retrieving revision 1.73 diff -p -u -r1.73 paste.c --- src/paste.c 3 Aug 2004 15:30:08 -0000 1.73 +++ src/paste.c 2 Sep 2004 23:47:43 -0000 @@ -52,14 +52,6 @@ /* Indicates that no delimiter should be added in the current position. */ #define EMPTY_DELIM '\0' -static FILE dummy_closed; -/* Element marking a file that has reached EOF and been closed. */ -#define CLOSED (&dummy_closed) - -static FILE dummy_endlist; -/* Element marking end of list of open files. */ -#define ENDLIST (&dummy_endlist) - /* Name this program was run with. */ char *program_name; @@ -154,13 +146,19 @@ paste_parallel (size_t nfiles, char **fn round, the string of delimiters must be preserved. delbuf[0] through delbuf[nfiles] store the delimiters for closed files. */ - char *delbuf; - FILE **fileptr; /* Streams open to the files to process. */ - size_t files_open; /* Number of files still open to process. */ - bool opened_stdin = false; /* true if any fopen got fd == STDIN_FILENO */ + char *delbuf = xmalloc (nfiles + 2); + + /* Streams open to the files to process. */ + FILE **fileptr = xnmalloc (nfiles + 1, sizeof *fileptr); + + /* Which of these streams are closed. */ + bool *closed = xcalloc (nfiles, sizeof *closed); + + /* Number of files still open to process. */ + size_t files_open; - delbuf = xmalloc (nfiles + 2); - fileptr = xnmalloc (nfiles + 1, sizeof *fileptr); + /* True if any fopen got fd == STDIN_FILENO. */ + bool opened_stdin = false; /* Attempt to open all files. This could be expanded to an infinite number of files, but at the (considerable) expense of remembering @@ -183,7 +181,7 @@ paste_parallel (size_t nfiles, char **fn } } - fileptr[files_open] = ENDLIST; + fileptr[files_open] = NULL; if (opened_stdin && have_read_stdin) error (EXIT_FAILURE, 0, _("standard input is closed")); @@ -200,11 +198,11 @@ paste_parallel (size_t nfiles, char **fn size_t delims_saved = 0; /* Number of delims saved in `delbuf'. */ size_t i; - for (i = 0; fileptr[i] != ENDLIST && files_open; i++) + for (i = 0; fileptr[i] && files_open; i++) { int chr IF_LINT (= 0); /* Input character. */ size_t line_length = 0; /* Number of chars in line. */ - if (fileptr[i] != CLOSED) + if (! closed[i]) { chr = getc (fileptr[i]); if (chr != EOF && delims_saved) @@ -227,7 +225,7 @@ paste_parallel (size_t nfiles, char **fn { /* EOF, read error, or closed file. If an EOF or error, close the file and mark it in the list. */ - if (fileptr[i] != CLOSED) + if (! closed[i]) { if (ferror (fileptr[i])) { @@ -242,11 +240,11 @@ paste_parallel (size_t nfiles, char **fn ok = false; } - fileptr[i] = CLOSED; + closed[i] = true; files_open--; } - if (fileptr[i + 1] == ENDLIST) + if (! fileptr[i + 1]) { /* End of this output line. Is this the end of the whole thing? */ @@ -277,7 +275,7 @@ paste_parallel (size_t nfiles, char **fn somedone = true; /* Except for last file, replace last newline with delim. */ - if (fileptr[i + 1] != ENDLIST) + if (fileptr[i + 1]) { if (chr != '\n' && chr != EOF) putc (chr, stdout); @@ -297,6 +295,7 @@ paste_parallel (size_t nfiles, char **fn } } free (fileptr); + free (closed); free (delbuf); return ok; } _______________________________________________ Bug-coreutils mailing list [EMAIL PROTECTED] http://lists.gnu.org/mailman/listinfo/bug-coreutils