📄 ckufio.c
字号:
#endif /* NDGPWNAM *//* Define macros for getting file type */#ifdef OXOS/* Olivetti X/OS 2.3 has S_ISREG and S_ISDIR defined incorrectly, so we force their redefinition.*/#undef S_ISREG#undef S_ISDIR#endif /* OXOS */#ifdef UTSV /* Same deal for Amdahl UTSV */#undef S_ISREG#undef S_ISDIR#endif /* UTSV */#ifdef UNISYS52 /* And for UNISYS UTS V 5.2 */#undef S_ISREG#undef S_ISDIR#endif /* UNISYS52 */#ifdef ICLSVR3 /* And for old ICL versions */#undef S_ISREG#undef S_ISDIR#endif /* ICLSVR3 */#ifdef ISDIRBUG /* Also allow this from command line */#ifdef S_ISREG#undef S_ISREG#endif /* S_ISREG */#ifdef S_ISDIR#undef S_ISDIR#endif /* S_ISDIR */#endif /* ISDIRBUG */#ifndef S_ISREG#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)#endif /* S_ISREG */#ifndef S_ISDIR#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)#endif /* S_ISDIR *//* Define maximum length for a file name if not already defined */#ifdef QNX#ifdef _MAX_FNAME#define MAXNAMLEN _MAX_FNAME#else#define MAXNAMLEN 48#endif /* _MAX_FNAME */#else#ifndef MAXNAMLEN#ifdef sun#define MAXNAMLEN 255#else#ifdef FILENAME_MAX#define MAXNAMLEN FILENAME_MAX#else#ifdef NAME_MAX#define MAXNAMLEN NAME_MAX#else#ifdef _POSIX_NAME_MAX#define MAXNAMLEN _POSIX_NAME_MAX#else#ifdef _D_NAME_MAX#define MAXNAMLEN _D_NAME_MAX#else#ifdef DIRSIZ#define MAXNAMLEN DIRSIZ#else#define MAXNAMLEN 14#endif /* DIRSIZ */#endif /* _D_NAME_MAX */#endif /* _POSIX_NAME_MAX */#endif /* NAME_MAX */#endif /* FILENAME_MAX */#endif /* sun */#endif /* MAXNAMLEN */#endif /* QNX *//* Longest pathname ... *//* Beware: MAXPATHLEN is one of UNIX's dirty little secrets. Where is it defined? Who knows... <param.h>, <mod.h>, <unistd.h>, <limits.h>, ... There is not necessarily even a definition for it anywhere, or it might have another name. If you get it wrong, bad things happen with getcwd() and/or getwd(). If you allocate a buffer that is too short, getwd() might write over memory and getcwd() will fail with ERANGE. The definitions of these functions (e.g. in SVID or POSIX.1) do not tell you how to determine the maximum path length in order to allocate a buffer that is the right size.*/#ifdef BSD44#include <sys/param.h> /* For MAXPATHLEN */#endif /* BSD44 */#ifdef COHERENT#include <sys/param.h> /* for MAXPATHLEN, needed for -DDIRENT */#endif /* COHERENT */#ifdef MAXPATHLEN#ifdef MAXPATH#undef MAXPATH#endif /* MAXPATH */#define MAXPATH MAXPATHLEN#else#ifdef PATH_MAX#define MAXPATH PATH_MAX#else#ifdef _POSIX_PATH_MAX#define MAXPATH _POSIX_PATH_MAX#else#ifdef BSD42#define MAXPATH 1024#else#ifdef SVR4 #define MAXPATH 1024#else#define MAXPATH 255#endif /* SVR4 */#endif /* BSD42 */#endif /* _POSIX_PATH_MAX */#endif /* PATH_MAX */#endif /* MAXPATHLEN *//* Maximum number of filenames for wildcard expansion */#ifdef PROVX1#define MAXWLD 50#else#ifdef pdp11#define MAXWLD 50#else#ifdef BIGBUFOK#define MAXWLD 4096#else#define MAXWLD 1000#endif /* BIGBUFOK */#endif /* pdp11 */#endif /* PROVX1 *//* More internal function prototypes *//* * The path structure is used to represent the name to match. * Each slash-separated segment of the name is kept in one * such structure, and they are linked together, to make * traversing the name easier. */struct path { char npart[MAXNAMLEN+4]; /* name part of path segment */ struct path *fwd; /* forward ptr */};#ifndef NOPUSH_PROTOTYP( int shxpand, (char *, char *[], int ) );extern int nopush;#endif /* NOPUSH */_PROTOTYP( static int fgen, (char *, char *[], int ) );_PROTOTYP( static VOID traverse, (struct path *, char *, char *) );_PROTOTYP( static VOID addresult, (char *) );_PROTOTYP( static int match, (char *, char *) );_PROTOTYP( static char * whoami, (void) );#ifdef aegis_PROTOTYP( static char * xindex, (char *, char) );#endif /* aegis */_PROTOTYP( UID_T real_uid, (void) );_PROTOTYP( struct path *splitpath, (char *p) );_PROTOTYP( char * zdtstr, (time_t) );_PROTOTYP( time_t zstrdt, (char *, int) );/* Some systems define these symbols in include files, others don't... */#ifndef R_OK#define R_OK 4 /* For access */#endif /* R_OK */#ifndef W_OK#define W_OK 2#endif /* W_OK */#ifndef O_RDONLY#define O_RDONLY 000#endif /* O_RDONLY *//* Declarations */int maxnam = MAXNAMLEN; /* Available to the outside */int maxpath = MAXPATH;int ck_znewn = -1;FILE *fp[ZNFILS] = { /* File pointers */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };#ifdef OS2int ispipe[ZNFILS]; /* Flag for file is a pipe */#endif /* OS2 *//* Buffers and pointers used in buffered file input and output. */#ifdef DYNAMICextern char *zinbuffer, *zoutbuffer;#elseextern char zinbuffer[], zoutbuffer[];#endif /* DYNAMIC */extern char *zinptr, *zoutptr;extern int zincnt, zoutcnt;extern int wildxpand;extern UID_T real_uid();static long iflen = -1L; /* Input file length */static PID_T pid = 0; /* pid of child fork */static int fcount; /* Number of files in wild group */static char nambuf[MAXNAMLEN+4]; /* Buffer for a filename */#ifndef NOFRILLSstatic char zmbuf[200]; /* For mail, remote print strings */#endif /* NOFRILLS */#ifndef OS2/* static */ /* Not static, must be global now. */char **mtchs = NULL; /* Matches found for filename */char **mtchptr = NULL; /* Pointer to current match */#endif /* OS2 */#ifdef OS2#ifndef NT#define INCL_KBD#define INCL_DOSERRORS#define INCL_DOSFILEMGR#define INCL_DOSPROCESS#define INCL_DOSSEMAPHORES#include <os2.h>typedef unsigned short WORD;#undef COMMENT/* Get/Set All Extended Attributes support */ #define FreeMem(p) DosFreeMem(p)#define MAX_GEA 500L /* Max size for a GEA List */#define MAXEACOUNT 128 /* Max number of EA's supported */#define Ref_ASCIIZ 1 /* Reference type for DosEnumAttribute *//* Definition of level specifiers, required for File Info */#define GetInfoLevel1 1 /* Get info from SFT */#define GetInfoLevel2 2 /* Get size of FEAlist */#define GetInfoLevel3 3 /* Get FEAlist given the GEAlist */#define GetInfoLevel4 4 /* Get whole FEAlist */#define GetInfoLevel5 5 /* Get FSDname */#define SetInfoLevel1 1 /* Set info in SFT */#define SetInfoLevel2 2 /* Set FEAlist */FEA2LIST *pFEAList = 0; /* Pointer to buffer containing all EA information */ULONG os2attrs = FILE_NORMAL;extern unsigned int lf_opts;#else /* NT */#include <windows.h>#endif /* NT */char os2filename[MAXPATH];#endif /* OS2 *//* Z K S E L F -- Kill Self: log out own job, if possible. *//* Note, should get current pid, but if your system doesn't have *//* getppid(), then just kill(0,9)... */#ifndef SVR3#ifndef POSIX#ifndef OSFPC/* Already declared in unistd.h for SVR3 and POSIX */#ifdef CK_ANSICextern PID_T getppid(void);#else#ifndef PS2AIX10extern PID_T getppid();#endif /* PS2AIX10 */#endif /* CK_ANSIC */#endif /* OSFPC */#endif /* POSIX */#endif /* SVR3 */intzkself() { /* For "bye", but no guarantee! */#ifdef PROVX1 return(kill(0,9));#else#ifdef V7 return(kill(0,9));#else#ifdef TOWER1 return(kill(0,9));#else#ifdef FT18 return(kill(0,9));#else#ifdef aegis return(kill(0,9));#else#ifdef COHERENT return(kill((PID_T)getpid(),1));#else#ifdef OS2 exit(3); return(0);#else#ifdef PID_T exit(kill((PID_T)getppid(),1)); return(0);#else exit(kill(getppid(),1)); return(0);#endif#endif#endif#endif#endif#endif#endif#endif}/* Z O P E N I -- Open an existing file for input. */intzopeni(n,name) int n; char *name; { int x, y; debug(F111," zopeni",name,n); debug(F101," fp","", fp[n]); if (chkfn(n) != 0) return(0); zincnt = 0; /* Reset input buffer */ if (n == ZSYSFN) { /* Input from a system function? *//*** Note, this function should not be called with ZSYSFN ***//*** Always call zxcmd() directly, and give it the real file number ***//*** you want to use. ***/ debug(F110,"zopeni called with ZSYSFN, failing!",name,0); *nambuf = '\0'; /* No filename. */ return(0); /* fail. */#ifdef COMMENT return(zxcmd(n,name)); /* Try to fork the command */#endif } if (n == ZSTDIO) { /* Standard input? */ if (is_a_tty(0)) { fprintf(stderr,"Terminal input not allowed"); debug(F110,"zopeni: attempts input from unredirected stdin","",0); return(0); } fp[ZIFILE] = stdin;#ifdef OS2#ifdef NT _setmode(_fileno(stdin),O_BINARY);#else setmode(fileno(stdin),O_BINARY);#endif /* NT */#endif /* OS2 */ return(1); }#ifdef OS2 if (n == ZIFILE || n == ZRFILE) { strncpy( os2filename, name, MAXPATH ) ; errno = 0;#ifdef NT fp[n] = _fsopen(name,"rb",_SH_DENYWR); /* Binary mode */#else fp[n] = fopen(name,"rb");/* Binary mode */#endif /* NT */ if (fp[ZIFILE]) { x = ferror(fp[ZIFILE]);#ifdef ZDEBUG printf("ZOPENI errno=%d\n",errno); printf("ZOPENI ferror=%d\n",x);#endif /* ZDEBUG */ }#ifdef CK_LABELED if (binary == XYFT_L) { os2getattr(name); os2geteas(name); }#endif /* CK_LABELED */ } else#ifdef NT fp[n] = _fsopen(name,"rb",_SH_DENYWR); /* Real file, open it. */#else fp[n] = fopen(name,"rb");/* Real file, open it. */#endif /* NT */#else /* OS2 */ fp[n] = fopen(name,"r"); /* Real file, open it. */#endif /* OS2 */ debug(F111," zopeni", name, fp[n]);#ifdef ZDEBUG printf("ZOPENI fp[%d]=%ld\n",n,fp[n]);#endif /* ZDEBUG */ if (fp[n] == NULL) perror("zopeni"); else clearerr(fp[n]); return((fp[n] != NULL) ? 1 : 0);}/* Z O P E N O -- Open a new file for output. */intzopeno(n,name,zz,fcb)/* zopeno */ int n; char *name; struct zattr *zz; struct filinfo *fcb; { char p[8]; /* (===OS2 change===) *//* As of Version 5A, the attribute structure and the file information *//* structure are included in the arglist. */#ifdef DEBUG debug(F111,"zopeno",name,n); if (fcb) { debug(F101,"zopeno fcb disp","",fcb->dsp); debug(F101,"zopeno fcb type","",fcb->typ); debug(F101,"zopeno fcb char","",fcb->cs); } else { debug(F100,"zopeno fcb is NULL","",0); } if (n != ZDFILE) debug(F111," zopeno",name,n);#endif /* DEBUG */ if (chkfn(n) != 0) /* Already open? */ return(0); /* Nothing to do. */ if ((n == ZCTERM) || (n == ZSTDIO)) { /* Terminal or standard output */ fp[ZOFILE] = stdout;#ifdef DEBUG if (n != ZDFILE) debug(F101," fp[]=stdout", "", fp[n]);#endif /* DEBUG */ zoutcnt = 0; zoutptr = zoutbuffer; return(1); }/* A real file. Open it in desired mode (create or append). */ strcpy(p,"w"); /* Assume write/create mode */ if (fcb) { /* If called with an FCB... */ if (fcb->dsp == XYFZ_A) { /* Does it say Append? */ strcpy(p,"a"); /* Yes. */ debug(F100,"zopeno append","",0); } }#ifdef OS2 if (n == ZOFILE || n == ZSFILE) { /* OS/2 binary mode */ strncpy( os2filename, name, MAXPATH ) ; strcat(p,"b"); }#endif /* OS2 */ debug(F110,"zopeno fopen arg",p,0); fp[n] = fopen(name,p); /* Try to open the file */#ifdef ZDEBUG printf("ZOPENO fp[%d]=%ld\n",n,fp[n]);#endif /* ZDEBUG */ if (fp[n] == NULL) { /* Failed */ debug(F101,"zopeno failed errno","",errno);#ifdef COMMENT /* Let upper levels print message. */ perror("Can't open output file");#endif /* COMMENT */ } else { /* Succeeded */ if (n == ZDFILE) /* If it's the debug log */ setbuf(fp[n],NULL); /* make it unbuffered */ else debug(F100, "zopeno ok", "", 0); } zoutcnt = 0; /* (PWP) reset output buffer */ zoutptr = zoutbuffer; return((fp[n] != NULL) ? 1 : 0);}/* Z C L O S E -- Close the given file. *//* Returns 0 if arg out of range, 1 if successful, -1 if close failed. */intzclose(n) int n; { int x, x2; if (chkfn(n) < 1) return(0); /* Check range of n */ if ((n == ZOFILE) && (zoutcnt > 0)) /* (PWP) output leftovers */ x2 = zoutdump(); else x2 = 0; x = 0; /* Initialize return code */ if (fp[ZSYSFN]#ifdef OS2 || ispipe[n] /* If file is really pipe */#endif /* OS2 */ ) { x = zclosf(n); /* do it specially */ } else { if ((fp[n] != stdout) && (fp[n] != stdin))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -