diff options
Diffstat (limited to 'posix')
-rw-r--r-- | posix/ChangeLog | 38 | ||||
-rw-r--r-- | posix/gawkmisc.c | 66 |
2 files changed, 90 insertions, 14 deletions
diff --git a/posix/ChangeLog b/posix/ChangeLog index 0325c92e..cba078f4 100644 --- a/posix/ChangeLog +++ b/posix/ChangeLog @@ -1,3 +1,29 @@ +Wed Mar 19 14:10:31 2003 Arnold D. Robbins <arnold@skeeve.com> + + This time for sure. + -- Bullwinkle + + * Release 3.1.2: Release tar file made. + +Tue Feb 4 14:28:06 2003 Arnold D. Robbins <arnold@skeeve.com> + + All relevant files: Copyright year updated to 2003. + +Tue Dec 17 11:05:11 2002 Arnold D. Robbins <arnold@skeeve.com> + + * gawkmisc.c (optimal_bufsize): Stat the file first, so that + stb is always valid for higher level code. + +Thu Nov 28 10:20:05 2002 Arnold D. Robbins <arnold@skeeve.com> + + * gawkmisc.c (optimal_bufsize): Enhance to use AWKBUFSIZE + environment variable for debugging. + +Tue Jun 11 22:18:42 2002 Stepan Kasal <kasal@math.cas.cz> + + * gawkmisc.c (DEFBLKSIZE): Add check for st_blksize > 0, + fixes weird bug on some versions of HP-UX. + Wed May 1 16:41:32 2002 Arnold D. Robbins <arnold@skeeve.com> * Release 3.1.1: Release tar file made. @@ -17,7 +43,7 @@ Sun Jan 28 15:50:02 2001 Eli Zaretskii <eliz@is.elta.co.il> Sun Dec 3 16:53:37 2000 Arnold D. Robbins <arnold@skeeve.com> - * gawkmisc.c (os_setbinmode): new function. + * gawkmisc.c (os_setbinmode): New function. Tue Nov 14 16:13:08 2000 Arnold D. Robbins <arnold@skeeve.com> @@ -27,11 +53,6 @@ Tue Nov 7 14:09:14 2000 Arnold D. Robbins <arnold@skeeve.com> * gawkmisc.c (os_is_setuid): new function. -Wed Jul 30 19:53:52 1997 Arnold D. Robbins <arnold@gnu.org> - - * Close-on-exec changes: - gawkmisc.c: (os_close_on_exec, os_isdir): new functions. - Mon Aug 7 15:23:00 2000 Arnold D. Robbins <arnold@skeeve.com> * Release 3.0.6: Release tar file made. @@ -44,6 +65,11 @@ Wed Jun 30 16:14:36 1999 Arnold D. Robbins <arnold@gnu.org> * Release 3.0.4: Release tar file made. This time for sure. +Wed Jul 30 19:53:52 1997 Arnold D. Robbins <arnold@gnu.org> + + * Close-on-exec changes: + gawkmisc.c: (os_close_on_exec, os_isdir): new functions. + Thu May 15 12:49:08 1997 Arnold D. Robbins <arnold@skeeve.atl.ga.us> * Release 3.0.3: Release tar file made. diff --git a/posix/gawkmisc.c b/posix/gawkmisc.c index 7f5e47ab..6ca9ee3d 100644 --- a/posix/gawkmisc.c +++ b/posix/gawkmisc.c @@ -1,6 +1,6 @@ /* gawkmisc.c --- miscellaneous gawk routines that are OS specific. - Copyright (C) 1986, 1988, 1989, 1991 - 1998, 2001, 2002 the Free Software Foundation, Inc. + Copyright (C) 1986, 1988, 1989, 1991 - 1998, 2001 - 2003 the Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -62,14 +62,63 @@ int flag; /* optimal_bufsize --- determine optimal buffer size */ -int +/* + * Enhance this for debugging purposes, as follows: + * + * Always stat the file, stat buffer is used by higher-level code. + * + * if (AWKBUFSIZE == "exact") + * return the file size + * else if (AWKBUFSIZE == a number) + * always return that number + * else + * if the size is < default_blocksize + * return the size + * else + * return default_blocksize + * end if + * endif + * + * Hair comes in an effort to only deal with AWKBUFSIZE + * once, the first time this routine is called, instead of + * every time. Performance, dontyaknow. + */ + +size_t optimal_bufsize(fd, stb) int fd; struct stat *stb; { + char *val; + static size_t env_val = 0; + static short first = TRUE; + static short exact = FALSE; + /* force all members to zero in case OS doesn't use all of them. */ memset(stb, '\0', sizeof(struct stat)); + /* always stat, in case stb is used by higher level code. */ + if (fstat(fd, stb) == -1) + fatal("can't stat fd %d (%s)", fd, strerror(errno)); + + if (first) { + first = FALSE; + + if ((val = getenv("AWKBUFSIZE")) != NULL) { + if (strcmp(val, "exact") == 0) + exact = TRUE; + else if (ISDIGIT(*val)) { + for (; *val && ISDIGIT(*val); val++) + env_val = (env_val * 10) + *val - '0'; + + return env_val; + } + } + } else if (! exact && env_val > 0) + return env_val; + /* else + fall through */ + /* * System V.n, n < 4, doesn't have the file system block size in the * stat structure. So we have to make some sort of reasonable @@ -77,16 +126,17 @@ struct stat *stb; * meant for in the first place. */ #ifdef HAVE_ST_BLKSIZE -#define DEFBLKSIZE (stb->st_blksize ? stb->st_blksize : BUFSIZ) +#define DEFBLKSIZE (stb->st_blksize > 0 ? stb->st_blksize : BUFSIZ) #else #define DEFBLKSIZE BUFSIZ #endif - if (fstat(fd, stb) == -1) - fatal("can't stat fd %d (%s)", fd, strerror(errno)); - if (S_ISREG(stb->st_mode) - && 0 < stb->st_size && stb->st_size < DEFBLKSIZE) /* small file */ - return stb->st_size; + if (S_ISREG(stb->st_mode) /* regular file */ + && 0 < stb->st_size /* non-zero size */ + && (stb->st_size < DEFBLKSIZE /* small file */ + || exact)) /* or debugging */ + return stb->st_size; /* use file size */ + return DEFBLKSIZE; } |