/* * gawkmisc.vms --- miscellanious gawk routines that are OS specific. */ /* * Copyright (C) 1986, 1988, 1989, 1991-1996, 2003, 2011 the Free Software Foundation, Inc. * * This file is part of GAWK, the GNU implementation of the * AWK Progamming Language. * * GAWK is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * GAWK is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ char quote = '\''; char *defpath = DEFPATH; char *deflibpath = DEFLIBPATH; char envsep = ','; /* gawk_name --- pull out the "gawk" part from how the OS called us */ char * gawk_name(filespec) const char *filespec; { char *p, *q; /* "device:[root.][directory.subdir]GAWK.EXE;n" -> "GAWK" */ p = strrchr(filespec, ']'); /* directory punctuation */ q = strrchr(filespec, '>'); /* alternate punct */ if (p == NULL || q > p) p = q; p = strdup(p == NULL ? filespec : (p + 1)); if ((q = strrchr(p, '.')) != NULL) *q = '\0'; /* strip .typ;vers */ return p; } /* os_arg_fixup --- fixup the command line */ void os_arg_fixup(argcp, argvp) int *argcp; char ***argvp; { (void) vms_arg_fixup(argcp, argvp); } /* os_devopen --- open special per-OS devices */ int os_devopen(name, flag) const char *name; int flag; { return vms_devopen(name, flag); } /* optimal_bufsize --- determine optimal buffer size */ size_t optimal_bufsize(fd, stb) int fd; struct stat *stb; { /* force all members to zero in case OS doesn't use all of them. */ memset(stb, '\0', sizeof(struct stat)); /* * These values correspond with the RMS multi-block count used by * vms_open() in vms/vms_misc.c. */ if (isatty(fd) > 0) return BUFSIZ; else if (fstat(fd, stb) < 0) return 8*512; /* conservative in case of DECnet access */ else return 32*512; } /* ispath --- return true if path has directory components */ int ispath(file) const char *file; { for (; *file; file++) { switch (*file) { case ':': case ']': case '>': case '/': return 1; } } return 0; } /* isdirpunct --- return true if char is a directory separator */ int isdirpunct(c) int c; { return (strchr(":]>/", c) != NULL); } /* os_close_on_exec --- set close on exec flag, print warning if fails */ void os_close_on_exec(fd, name, what, dir) int fd; const char *name, *what, *dir; { /* no-op */ } /* os_isdir --- is this an fd on a directory? */ #if ! defined(S_ISDIR) && defined(S_IFDIR) #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #endif int os_isdir(fd) int fd; { struct stat sbuf; return (fstat(fd, &sbuf) == 0 && S_ISDIR(sbuf.st_mode)); } /* os_isreadable --- fd can be read from */ int os_isreadable(const awk_input_buf_t *iobuf, bool *isdir) { *isdir = false; switch (iobuf->sbuf.st_mode & S_IFMT) { case S_IFREG: case S_IFCHR: /* ttys, /dev/null, .. */ #ifdef S_IFSOCK case S_IFSOCK: #endif #ifdef S_IFIFO case S_IFIFO: #endif return true; case S_IFDIR: *isdir = true; /* fall through */ default: return false; } } /* os_is_setuid --- true if running setuid root */ int os_is_setuid() { return 0; } /* os_setbinmode --- set binary mode on file */ int os_setbinmode (fd, mode) int fd, mode; { return 0; } /* os_restore_mode --- restore the original mode of the console device */ void os_restore_mode (fd) int fd; { /* no-op */ return; } /* files_are_same --- deal with VMS struct stat */ int files_are_same(char *newfile, SRCFILE *oldfile) { struct stat st, *f1, *f2; f1 = &st; if (stat(newfile, f1) != 0) return 0; f2 = &oldfile->sbuf; /* compare device string */ return (strcmp(f1->st_dev, f2->st_dev) == 0 /* and 48-bit file id cookie stored in 3 short ints */ && f1->st_ino[0] == f2->st_ino[0] && f1->st_ino[1] == f2->st_ino[1] && f1->st_ino[2] == f2->st_ino[2]); } int os_isatty(int fd) { return (isatty(fd) > 0); } void init_sockets(void) { }