1 /* gawkmisc.c --- miscellanious gawk routines that are OS specific.
3 Copyright (C) 1986, 1988, 1989, 1991 - 96 the Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 char *defpath = DEFPATH;
23 /* gawk_name --- pull out the "gawk" part from how the OS called us */
31 /* "path/name" -> "name" */
32 p = strrchr(filespec, '/');
33 return (p == NULL ? (char *) filespec : p + 1);
36 /* os_arg_fixup --- fixup the command line */
39 os_arg_fixup(argcp, argvp)
47 /* os_devopen --- open special per-OS devices */
50 os_devopen(name, flag)
55 return INVALID_HANDLE;
58 /* optimal_bufsize --- determine optimal buffer size */
61 optimal_bufsize(fd, stb)
65 /* force all members to zero in case OS doesn't use all of them. */
66 memset(stb, '\0', sizeof(struct stat));
69 * System V.n, n < 4, doesn't have the file system block size in the
70 * stat structure. So we have to make some sort of reasonable
71 * guess. We use stdio's BUFSIZ, since that is what it was
72 * meant for in the first place.
74 #ifdef HAVE_ST_BLKSIZE
75 #define DEFBLKSIZE (stb->st_blksize ? stb->st_blksize : BUFSIZ)
77 #define DEFBLKSIZE BUFSIZ
82 if (fstat(fd, stb) == -1)
83 fatal("can't stat fd %d (%s)", fd, strerror(errno));
84 if (lseek(fd, (off_t)0, 0) == -1) /* not a regular file */
86 if (stb->st_size > 0 && stb->st_size < DEFBLKSIZE) /* small file */
91 /* ispath --- return true if path has directory components */
97 return (strchr(file, '/') != NULL);
100 /* isdirpunct --- return true if char is a directory separator */