|
|
1.1 ! root 1: #include <CC/sys/types.h> ! 2: #include <CC/sys/stat.h> ! 3: #include <sgtty.h> ! 4: #include <stdio.h> ! 5: #include <sys/param.h> ! 6: #include <sys/dir.h> ! 7: #include <errno.h> ! 8: #include "lib.h" ! 9: #include <ctype.h> ! 10: #include <pads.pub> ! 11: SRCFILE("lib.c") ! 12: ! 13: char *index(register char *sp, char c) ! 14: { ! 15: do { ! 16: if (*sp == c) return sp; ! 17: } while (*sp++); ! 18: return 0; ! 19: } ! 20: ! 21: char *rindex(register char *sp, char c) ! 22: { ! 23: register char *r = 0; ! 24: ! 25: do { ! 26: if (*sp == c) ! 27: r = sp; ! 28: } while (*sp++); ! 29: return r; ! 30: } ! 31: ! 32: char *basename(char *path) ! 33: { ! 34: char *lsi = rindex(path, '/'); ! 35: return lsi ? lsi+1 : path; ! 36: } ! 37: ! 38: char *slashname(char *path) ! 39: { ! 40: return sf("%0.*s", strlen(path)-strlen(basename(path)), path); ! 41: } ! 42: ! 43: int alldigits(char *p) ! 44: { ! 45: if( !p ) return 0; ! 46: while( isdigit(*p) ) ++p; ! 47: return !*p; ! 48: } ! 49: ! 50: char *Name(char *s, int i) ! 51: { ! 52: static char buf[8][32]; ! 53: static cycle; ! 54: char *t = buf[(cycle++,cycle%=8)]; ! 55: sprintf( t, s, i ); ! 56: return t; ! 57: } ! 58: ! 59: char *SysErr(char *s) ! 60: { ! 61: extern int errno, sys_nerr; ! 62: extern char *sys_errlist[]; ! 63: ! 64: if( errno>=sys_nerr || errno<1 ) return sf( "%s errno=%d", s, errno); ! 65: return sf( "%s %s", s, sys_errlist[errno] ); ! 66: } ! 67: ! 68: char *strcatfmt(char *s, char *f ... ) ! 69: { ! 70: int *a = (int*)&f; ! 71: sprintf( &s[strlen(s)], f, a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8] ); ! 72: return s; ! 73: } ! 74: ! 75: int ReadOK( int fd, char *addr, int req ) ! 76: { ! 77: int got; ! 78: ! 79: got = read(fd,addr,req); ! 80: trace( "ReadOK(%d,%d,%d) %d", fd, addr, req, got ); ! 81: return got == req; ! 82: } ! 83: ! 84: int WriteOK( int fd, char *addr, int req ) ! 85: { ! 86: int got; ! 87: ! 88: got = write(fd,addr,req); ! 89: trace( "WriteOK(%d,%d,%d) %d", fd, addr, req, got ); ! 90: return got == req; ! 91: } ! 92: ! 93: long modified( int fd ) ! 94: { ! 95: struct stat buf; ! 96: ! 97: fstat( fd, &buf ); ! 98: trace( "fd=%d buf.st_mtime=%d", fd, buf.st_mtime ); ! 99: return buf.st_mtime; ! 100: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.