LIB.T
上传用户:jnzhq888
上传日期:2007-01-18
资源大小:51694k
文件大小:969k
- 37749 return -1L;
- 37750 }
- 37751 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/other/telldir.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 37800 /* telldir() Author: Kees J. Bot
- 37801 * 24 Apr 1989
- 37802 */
- 37803 #define nil 0
- 37804 #include <lib.h>
- 37805 #include <sys/types.h>
- 37806 #include <dirent.h>
- 37807 #include <errno.h>
- 37808
- 37809 off_t telldir(DIR *dp)
- 37810 /* Return the current read position in a directory. */
- 37811 {
- 37812 if (dp == nil) { errno= EBADF; return -1; }
- 37813
- 37814 return dp->_pos;
- .Op 375 src/lib/other/telldir.c
- 37815 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/other/termcap.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 37900 /*
- 37901 * termcap.c V1.1 20/7/87 agc Joypace Ltd
- 37902 *
- 37903 * Copyright Joypace Ltd, London, UK, 1987. All rights reserved.
- 37904 * This file may be freely distributed provided that this notice
- 37905 * remains attached.
- 37906 *
- 37907 * A public domain implementation of the termcap(3) routines.
- 37908 *
- 37909 *
- 37910 *
- 37911 * Klamer Schutte V1.2 Nov. 1988
- 37912 *
- 37913 * - Can match multiple terminal names [tgetent]
- 37914 * - Removal of **area assignments [tgetstr]
- 37915 *
- 37916 * Terrence W. Holm V1.3 May, Sep, Oct. 1988
- 37917 *
- 37918 * - Correct when TERM != name and TERMCAP is defined [tgetent]
- 37919 * - Correct the comparison for the terminal name [tgetent]
- 37920 * - Correct the value of ^x escapes [tgetstr]
- 37921 * - Added %r to reverse row/column [tgoto]
- 37922 * - Fixed end of definition test [tgetnum/flag/str]
- 37923 *
- 37924 * Terrence W. Holm V1.4 Jan. 1989
- 37925 *
- 37926 * - Incorporated Klamer's V1.2 fixes into V1.3
- 37927 * - Added %d, (old %d is now %2) [tgoto]
- 37928 * - Allow '#' comments in definition file [tgetent]
- 37929 */
- 37930
- 37931 #include <lib.h>
- 37932 #include <termcap.h>
- 37933 #include <ctype.h>
- 37934 #include <stdlib.h>
- 37935 #include <string.h>
- 37936 #include <stdio.h>
- 37937
- 37938 char *capab = (char *)NULL; /* the capability itself */
- 37939
- 37940 #if 0
- 37941 /* The following are not yet used. */
- 37942 extern short ospeed; /* output speed */
- 37943 extern char PC; /* padding character */
- 37944 extern char *BC; /* back cursor movement */
- 37945 extern char *UP; /* up cursor movement */
- 37946 #endif
- 37947
- 37948 /*
- 37949 * tgetent - get the termcap entry for terminal name, and put it
- .Ep 376 src/lib/other/termcap.c
- 37950 * in bp (which must be an array of 1024 chars). Returns 1 if
- 37951 * termcap entry found, 0 if not found, and -1 if file not found.
- 37952 */
- 37953
- 37954 int tgetent(bp, name)
- 37955 char *bp;
- 37956 char *name;
- 37957 {
- 37958 FILE *fp;
- 37959 char *file;
- 37960 char *term;
- 37961 short len = strlen(name);
- 37962
- 37963 capab = bp;
- 37964
- 37965 /* If TERMCAP begins with a '/' then use TERMCAP as the path */
- 37966 /* Name of the termcap definitions file. If TERMCAP is a */
- 37967 /* Definition and TERM equals "name" then use TERMCAP as the */
- 37968 /* Definition. Otherwise use "/etc/termcap" as the path name. */
- 37969
- 37970 if ((file = getenv("TERMCAP")) == (char *)NULL)
- 37971 file = "/etc/termcap";
- 37972 else if (*file != '/')
- 37973 if ((term = getenv("TERM")) != (char *)NULL && strcmp(term, name) == 0) {
- 37974 *bp = ' ';
- 37975 strncat(bp, file, 1023);
- 37976 return(1);
- 37977 } else
- 37978 file = "/etc/termcap";
- 37979
- 37980 if ((fp = fopen(file, "r")) == (FILE *) NULL) {
- 37981 capab = (char *)NULL; /* no valid termcap */
- 37982 return(-1);
- 37983 }
- 37984 for (;;) {
- 37985 /* Read in each definition */
- 37986 int def_len = 0;
- 37987 char *cp = bp;
- 37988
- 37989 do {
- 37990 if (fgets(&bp[def_len], (unsigned int)(1024 - def_len), fp) == (char *)NULL) {
- 37991 fclose(fp);
- 37992 capab = (char *)NULL; /* no valid termcap */
- 37993 return(0);
- 37994 }
- 37995 def_len = strlen(bp) - 2;
- 37996 } while (bp[def_len] == '\');
- 37997
- 37998 while (isspace(*cp)) cp++;
- 37999
- 38000 /* Comment lines start with a '#' */
- 38001 if (*cp == '#') continue;
- 38002
- 38003 /* See if any of the terminal names in this definition */
- 38004 /* Match "name". */
- 38005
- 38006 do {
- 38007 if (strncmp(name, cp, len) == 0 &&
- 38008 (cp[len] == '|' || cp[len] == ':')) {
- 38009 fclose(fp);
- .Op 377 src/lib/other/termcap.c
- 38010 return(1);
- 38011 }
- 38012 while ((*cp) && (*cp != '|') && (*cp != ':')) cp++;
- 38013 } while (*cp++ == '|');
- 38014 }
- 38015 }
-
-
- 38018 /*
- 38019 * tgetnum - get the numeric terminal capability corresponding
- 38020 * to id. Returns the value, -1 if invalid.
- 38021 */
- 38022
- 38023 int tgetnum(id)
- 38024 char *id;
- 38025 {
- 38026 register char *cp = capab;
- 38027
- 38028 if (cp == (char *)NULL || id == (char *)NULL) return(-1);
- 38029
- 38030 for (;;) {
- 38031 while (*cp++ != ':')
- 38032 if (cp[-1] == ' ') return(-1);
- 38033
- 38034 while (isspace(*cp)) cp++;
- 38035
- 38036 if (strncmp(cp, id, 2) == 0 && cp[2] == '#') return(atoi(cp + 3));
- 38037 }
- 38038 }
-
-
- 38041 /*
- 38042 * tgetflag - get the boolean flag corresponding to id. Returns -1
- 38043 * if invalid, 0 if the flag is not in termcap entry, or 1 if it is
- 38044 * present.
- 38045 */
- 38046
- 38047 int tgetflag(id)
- 38048 char *id;
- 38049 {
- 38050 register char *cp = capab;
- 38051
- 38052 if (cp == (char *)NULL || id == (char *)NULL) return(-1);
- 38053
- 38054 for (;;) {
- 38055 while (*cp++ != ':')
- 38056 if (cp[-1] == ' ') return(0);
- 38057
- 38058 while (isspace(*cp)) cp++;
- 38059
- 38060 if (strncmp(cp, id, 2) == 0) return(1);
- 38061 }
- 38062 }
-
-
- 38065 /*
- 38066 * tgetstr - get the string capability corresponding to id and place
- 38067 * it in area (advancing area at same time). Expand escape sequences
- 38068 * etc. Returns the string, or NULL if it can't do it.
- 38069 */
- .Ep 378 src/lib/other/termcap.c
- 38070
- 38071 char *tgetstr(id, area)
- 38072 char *id;
- 38073 char **area;
- 38074 {
- 38075 register char *cp = capab;
- 38076 register char *wsp = *area; /* workspace pointer */
- 38077
- 38078 if (cp == (char *)NULL || id == (char *)NULL) return((char *)NULL);
- 38079
- 38080 for (;;) {
- 38081 while (*cp++ != ':')
- 38082 if (cp[-1] == ' ') return((char *)NULL);
- 38083
- 38084 while (isspace(*cp)) cp++;
- 38085
- 38086 if (strncmp(cp, id, 2) == 0 && cp[2] == '=') {
- 38087 for (cp += 3; *cp && *cp != ':'; wsp++, cp++) switch (*cp) {
- 38088 case '^':
- 38089 *wsp = *++cp - '@';
- 38090 break;
- 38091
- 38092 case '\':
- 38093 switch (*++cp) {
- 38094 case 'E':
- 38095 *wsp = ' 33';
- 38096 break;
- 38097 case 'n':
- 38098 *wsp = 'n';
- 38099 break;
- 38100 case 'r':
- 38101 *wsp = 'r';
- 38102 break;
- 38103 case 't':
- 38104 *wsp = 't';
- 38105 break;
- 38106 case 'b':
- 38107 *wsp = 'b';
- 38108 break;
- 38109 case 'f':
- 38110 *wsp = 'f';
- 38111 break;
- 38112 case '0':
- 38113 case '1':
- 38114 case '2':
- 38115 case '3':
- 38116 {
- 38117 int i;
- 38118 int t = 0;
- 38119 for (i = 0; i < 3 &&
- 38120 isdigit(*cp); ++i, ++cp)
- 38121 t = t * 8 + *cp - '0';
- 38122 *wsp = t;
- 38123 cp--;
- 38124 break;
- 38125 }
- 38126 default:
- 38127 *wsp = *cp;
- 38128 }
- 38129 break;
- .Op 379 src/lib/other/termcap.c
- 38130
- 38131 default: *wsp = *cp;
- 38132 }
- 38133
- 38134 *wsp++ = ' ';
- 38135
- 38136 {
- 38137 char *ret = *area;
- 38138 *area = wsp;
- 38139 return(ret);
- 38140 }
- 38141 }
- 38142 } /* end for(;;) */
- 38143 }
-
-
-
- 38147 /*
- 38148 * tgoto - given the cursor motion string cm, make up the string
- 38149 * for the cursor to go to (destcol, destline), and return the string.
- 38150 * Returns "OOPS" if something's gone wrong, or the string otherwise.
- 38151 */
- 38152
- 38153 char *tgoto(cm, destcol, destline)
- 38154 char *cm;
- 38155 int destcol;
- 38156 int destline;
- 38157 {
- 38158 PRIVATE char ret[24];
- 38159 char *rp = ret;
- 38160 int incr = 0;
- 38161 int argno = 0;
- 38162 int numval;
- 38163
- 38164 for (; *cm; cm++) {
- 38165 if (*cm == '%') {
- 38166 switch (*++cm) {
- 38167 case 'i': incr = 1; break;
- 38168
- 38169 case 'r': argno = 1; break;
- 38170
- 38171 case '+':
- 38172 numval = (argno == 0 ? destline : destcol);
- 38173 *rp++ = numval + incr + *++cm;
- 38174 argno = 1 - argno;
- 38175 break;
- 38176
- 38177 case '2':
- 38178 numval = (argno == 0 ? destline : destcol);
- 38179 numval = (numval + incr) % 100;
- 38180 *rp++ = '0' + (numval / 10);
- 38181 *rp++ = '0' + (numval % 10);
- 38182 argno = 1 - argno;
- 38183 break;
- 38184
- 38185 case 'd':
- 38186 numval = (argno == 0 ? destline : destcol);
- 38187 numval = (numval + incr) % 1000;
- 38188 if (numval > 99) *rp++ = '0' + (numval / 100);
- 38189 if (numval > 9) *rp++ = '0' + (numval / 10) % 10;
- .Ep 380 src/lib/other/termcap.c
- 38190 *rp++ = '0' + (numval % 10);
- 38191 argno = 1 - argno;
- 38192 break;
- 38193
- 38194 case '%': *rp++ = '%'; break;
- 38195
- 38196 default: return("OOPS");
- 38197 }
- 38198
- 38199 } else
- 38200 *rp++ = *cm;
- 38201 }
- 38202
- 38203 *rp = ' ';
- 38204 return(ret);
- 38205 }
-
-
-
- 38209 /*
- 38210 * tputs - put the string cp out onto the terminal, using the function
- 38211 * outc. This should do padding for the terminal, but I can't find a
- 38212 * terminal that needs padding at the moment...
- 38213 */
- 38214
- 38215 int tputs(cp, affcnt, outc)
- 38216 register char *cp;
- 38217 int affcnt;
- 38218 _PROTOTYPE( void (*outc), (int ch));
- 38219 {
- 38220 if (cp == (char *)NULL) return(1);
- 38221 /* Do any padding interpretation - left null for MINIX just now */
- 38222 while (*cp) (*outc) (*cp++);
- 38223 return(1);
- 38224 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/other/ttyname.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 38300 /* ttyname.c POSIX 4.7.2
- 38301 * char *ttyname(int fildes);
- 38302 *
- 38303 * Determines name of a terminal device.
- 38304 */
- 38305
- 38306 #include <lib.h>
- 38307 #include <sys/stat.h>
- 38308 #include <dirent.h>
- 38309 #include <fcntl.h>
- 38310 #include <stddef.h>
- 38311 #include <string.h>
- 38312 #include <unistd.h>
- 38313
- 38314 PRIVATE char base[] = "/dev";
- .Op 381 src/lib/other/ttyname.c
- 38315 PRIVATE char path[sizeof(base) + 1 + NAME_MAX]; /* extra 1 for '/' */
- 38316
- 38317 PUBLIC char *ttyname(fildes)
- 38318 int fildes;
- 38319 {
- 38320 DIR *devices;
- 38321 struct dirent *entry;
- 38322 struct stat tty_stat;
- 38323 struct stat dev_stat;
- 38324
- 38325 /* Simple first test: file descriptor must be a character device */
- 38326 if (fstat(fildes, &tty_stat) < 0 || !S_ISCHR(tty_stat.st_mode))
- 38327 return (char *) NULL;
- 38328
- 38329 /* Open device directory for reading */
- 38330 if ((devices = opendir(base)) == (DIR *) NULL)
- 38331 return (char *) NULL;
- 38332
- 38333 /* Scan the entries for one that matches perfectly */
- 38334 while ((entry = readdir(devices)) != (struct dirent *) NULL) {
- 38335 if (tty_stat.st_ino != entry->d_ino)
- 38336 continue;
- 38337 strcpy(path, base);
- 38338 strcat(path, "/");
- 38339 strcat(path, entry->d_name);
- 38340 if (stat(path, &dev_stat) < 0 || !S_ISCHR(dev_stat.st_mode))
- 38341 continue;
- 38342 if (tty_stat.st_ino == dev_stat.st_ino &&
- 38343 tty_stat.st_dev == dev_stat.st_dev &&
- 38344 tty_stat.st_rdev == dev_stat.st_rdev) {
- 38345 closedir(devices);
- 38346 return path;
- 38347 }
- 38348 }
- 38349
- 38350 closedir(devices);
- 38351 return (char *) NULL;
- 38352 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/other/ttyslot.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 38400 /*
- 38401 ttyslot.c
- 38402
- 38403 Return the index in the utmp file for the current user's terminal. The
- 38404 current user's terminal is the first file descriptor in the range 0..2
- 38405 for which ttyname() returns a name. The index is the line number in the
- 38406 /etc/ttytab file. 0 will be returned in case of an error.
- 38407
- 38408 Created: Oct 11, 1992 by Philip Homburg
- 38409 */
- 38410
- 38411 #define _MINIX_SOURCE
- 38412
- 38413 #include <sys/types.h>
- 38414 #include <ttyent.h>
- .Ep 382 src/lib/other/ttyslot.c
- 38415 #include <string.h>
- 38416 #include <unistd.h>
- 38417
- 38418 int ttyslot()
- 38419 {
- 38420 int slot;
- 38421
- 38422 slot= fttyslot(0);
- 38423 if (slot == 0) slot= fttyslot(1);
- 38424 if (slot == 0) slot= fttyslot(2);
- 38425 return slot;
- 38426 }
-
- 38428 int fttyslot(fd)
- 38429 int fd;
- 38430 {
- 38431 char *tname;
- 38432 int lineno;
- 38433 struct ttyent *ttyp;
- 38434
- 38435 tname= ttyname(fd);
- 38436 if (tname == NULL) return 0;
- 38437
- 38438 /* Assume that tty devices are in /dev */
- 38439 if (strncmp(tname, "/dev/", 5) != 0)
- 38440 return 0; /* Malformed tty name. */
- 38441 tname += 5;
- 38442
- 38443 /* Scan /etc/ttytab. */
- 38444 lineno= 1;
- 38445 while ((ttyp= getttyent()) != NULL)
- 38446 {
- 38447 if (strcmp(tname, ttyp->ty_name) == 0)
- 38448 {
- 38449 endttyent();
- 38450 return lineno;
- 38451 }
- 38452 lineno++;
- 38453 }
- 38454 /* No match */
- 38455 endttyent();
- 38456 return 0;
- 38457 }
-
- 38459 /*
- 38460 * $PchHeader: /mount/hd2/minix/lib/misc/RCS/ttyslot.c,v 1.3 1994/12/22 13:49:12 philip Exp $
- 38461 */
- .Op 383 src/lib/posix/__exit.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/__exit.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 38500 #define _exit __exit
- 38501 #include <lib.h>
- 38502 #include <unistd.h>
- 38503
- 38504 PUBLIC void _exit(status)
- 38505 int status;
- 38506 {
- 38507 message m;
- 38508
- 38509 m.m1_i1 = status;
- 38510 _syscall(MM, EXIT, &m);
- 38511 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_access.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 38600 #include <lib.h>
- 38601 #define access _access
- 38602 #include <unistd.h>
- 38603
- 38604 PUBLIC int access(name, mode)
- 38605 _CONST char *name;
- 38606 int mode;
- 38607 {
- 38608 message m;
- 38609
- 38610 m.m3_i2 = mode;
- 38611 _loadname(name, &m);
- 38612 return(_syscall(FS, ACCESS, &m));
- 38613 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_alarm.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 38700 #include <lib.h>
- 38701 #define alarm _alarm
- 38702 #include <unistd.h>
- 38703
- 38704 PUBLIC unsigned int alarm(sec)
- 38705 unsigned int sec;
- 38706 {
- 38707 message m;
- 38708
- 38709 m.m1_i1 = (int) sec;
- 38710 return( (unsigned) _syscall(MM, ALARM, &m));
- 38711 }
- .Ep 384 src/lib/posix/_cfgetispeed.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_cfgetispeed.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 38800 /*
- 38801 posix/_cfgetispeed
- 38802
- 38803 Created: June 11, 1993 by Philip Homburg
- 38804 */
- 38805
- 38806 #include <termios.h>
- 38807
- 38808 speed_t _cfgetispeed(const struct termios *termios_p)
- 38809 {
- 38810 return termios_p->c_ispeed;
- 38811 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_cfgetospeed.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 38900 /*
- 38901 posix/_cfgetospeed
- 38902
- 38903 Created: June 11, 1993 by Philip Homburg
- 38904 */
- 38905
- 38906 #include <termios.h>
- 38907
- 38908 speed_t _cfgetospeed(const struct termios *termios_p)
- 38909 {
- 38910 return termios_p->c_ospeed;
- 38911 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_cfsetispeed.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 39000 /*
- 39001 posix/_cfsetispeed
- 39002
- 39003 Created: June 11, 1993 by Philip Homburg
- 39004 */
- 39005
- 39006 #include <termios.h>
- 39007
- 39008 int _cfsetispeed(struct termios *termios_p, speed_t speed)
- 39009 {
- 39010 termios_p->c_ispeed= speed;
- 39011 return 0;
- 39012 }
- .Op 385 src/lib/posix/_cfsetospeed.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_cfsetospeed.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 39100 /*
- 39101 posix/_cfsetospeed
- 39102
- 39103 Created: June 11, 1993 by Philip Homburg
- 39104 */
- 39105
- 39106 #include <termios.h>
- 39107
- 39108 int _cfsetospeed(struct termios *termios_p, speed_t speed)
- 39109 {
- 39110 termios_p->c_ospeed= speed;
- 39111 return 0;
- 39112 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_chdir.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 39200 #include <lib.h>
- 39201 #define chdir _chdir
- 39202 #include <unistd.h>
- 39203
- 39204 PUBLIC int chdir(name)
- 39205 _CONST char *name;
- 39206 {
- 39207 message m;
- 39208
- 39209 _loadname(name, &m);
- 39210 return(_syscall(FS, CHDIR, &m));
- 39211 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_chmod.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 39300 #include <lib.h>
- 39301 #define chmod _chmod
- 39302 #include <sys/stat.h>
- 39303
- 39304 PUBLIC int chmod(name, mode)
- 39305 _CONST char *name;
- 39306 Mode_t mode;
- 39307 {
- 39308 message m;
- 39309
- 39310 m.m3_i2 = mode;
- 39311 _loadname(name, &m);
- 39312 return(_syscall(FS, CHMOD, &m));
- 39313 }
- .Ep 386 src/lib/posix/_chown.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_chown.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 39400 #include <lib.h>
- 39401 #define chown _chown
- 39402 #include <string.h>
- 39403 #include <unistd.h>
- 39404
- 39405 PUBLIC int chown(name, owner, grp)
- 39406 _CONST char *name;
- 39407 Uid_t owner;
- 39408 Gid_t grp;
- 39409 {
- 39410 message m;
- 39411
- 39412 m.m1_i1 = strlen(name) + 1;
- 39413 m.m1_i2 = owner;
- 39414 m.m1_i3 = grp;
- 39415 m.m1_p1 = (char *) name;
- 39416 return(_syscall(FS, CHOWN, &m));
- 39417 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_chroot.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 39500 #include <lib.h>
- 39501 #define chroot _chroot
- 39502 #include <unistd.h>
- 39503
- 39504 PUBLIC int chroot(name)
- 39505 _CONST char *name;
- 39506 {
- 39507 message m;
- 39508
- 39509 _loadname(name, &m);
- 39510 return(_syscall(FS, CHROOT, &m));
- 39511 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_close.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 39600 #include <lib.h>
- 39601 #define close _close
- 39602 #include <unistd.h>
- 39603
- 39604 PUBLIC int close(fd)
- 39605 int fd;
- 39606 {
- 39607 message m;
- 39608
- 39609 m.m1_i1 = fd;
- .Op 387 src/lib/posix/_close.c
- 39610 return(_syscall(FS, CLOSE, &m));
- 39611 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_closedir.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 39700 /* closedir() Author: Kees J. Bot
- 39701 * 24 Apr 1989
- 39702 */
- 39703 #define nil 0
- 39704 #include <lib.h>
- 39705 #define close _close
- 39706 #define closedir _closedir
- 39707 #include <sys/types.h>
- 39708 #include <dirent.h>
- 39709 #include <unistd.h>
- 39710 #include <stdlib.h>
- 39711 #include <errno.h>
- 39712
- 39713 int closedir(DIR *dp)
- 39714 /* Finish reading a directory. */
- 39715 {
- 39716 int d;
- 39717
- 39718 if (dp == nil) { errno= EBADF; return -1; }
- 39719
- 39720 d= dp->_fd;
- 39721 free((void *) dp);
- 39722 return close(d);
- 39723 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_creat.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 39800 #include <lib.h>
- 39801 #define creat _creat
- 39802 #include <fcntl.h>
- 39803
- 39804 PUBLIC int creat(name, mode)
- 39805 _CONST char *name;
- 39806 Mode_t mode;
- 39807 {
- 39808 message m;
- 39809
- 39810 m.m3_i2 = mode;
- 39811 _loadname(name, &m);
- 39812 return(_syscall(FS, CREAT, &m));
- 39813 }
- .Ep 388 src/lib/posix/_dup.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_dup.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 39900 #include <lib.h>
- 39901 #define dup _dup
- 39902 #define fcntl _fcntl
- 39903 #include <fcntl.h>
- 39904 #include <unistd.h>
- 39905
- 39906 PUBLIC int dup(fd)
- 39907 int fd;
- 39908 {
- 39909 return(fcntl(fd, F_DUPFD, 0));
- 39910 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_dup2.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 40000 #include <lib.h>
- 40001 #define close _close
- 40002 #define dup2 _dup2
- 40003 #define fcntl _fcntl
- 40004 #include <fcntl.h>
- 40005 #include <unistd.h>
- 40006
- 40007 PUBLIC int dup2(fd, fd2)
- 40008 int fd, fd2;
- 40009 {
- 40010 /* The behavior of dup2 is defined by POSIX in 6.2.1.2 as almost, but not
- 40011 * quite the same as fcntl.
- 40012 */
- 40013
- 40014 if (fd2 < 0 || fd2 > OPEN_MAX) {
- 40015 errno = EBADF;
- 40016 return(-1);
- 40017 }
- 40018
- 40019 /* Check to see if fildes is valid. */
- 40020 if (fcntl(fd, F_GETFL) < 0) {
- 40021 /* 'fd' is not valid. */
- 40022 return(-1);
- 40023 } else {
- 40024 /* 'fd' is valid. */
- 40025 if (fd == fd2) return(fd2);
- 40026 close(fd2);
- 40027 return(fcntl(fd, F_DUPFD, fd2));
- 40028 }
- 40029 }
- .Op 389 src/lib/posix/_exec.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_exec.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 40100 #include <lib.h>
- 40101 #define execl _execl
- 40102 #define execle _execle
- 40103 #define execv _execv
- 40104 #define execve _execve
- 40105 #define sbrk _sbrk
- 40106 #include <minix/minlib.h>
- 40107 #include <stdarg.h>
- 40108 #include <string.h>
- 40109 #include <unistd.h>
- 40110
- 40111 extern char **environ;
- 40112
- 40113 #define PTRSIZE (sizeof(char *))
- 40114
- 40115 #ifdef _ANSI
- 40116 PUBLIC int execl(const char *name, const char *arg, ...)
- 40117 #else
- 40118 PUBLIC int execl(name)
- 40119 char *name;
- 40120 #endif
- 40121 {
- 40122 va_list argp;
- 40123 int result;
- 40124
- 40125 va_start(argp, name);
- 40126
- 40127 /* The following cast of argp is not portable. Doing it right by copying
- 40128 * the args to a true array will cost as much as ARG_MAX bytes of space.
- 40129 */
- 40130 result = execve(name, (char **) argp, environ);
- 40131 va_end(argp);
- 40132 return(result);
- 40133 }
-
-
- 40136 #ifdef _ANSI
- 40137 PUBLIC int execle(const char *name, const char *arg, ...)
- 40138 #else
- 40139 PUBLIC int execle(name)
- 40140 char *name;
- 40141 #endif
- 40142 {
- 40143 va_list argp;
- 40144 char **p;
- 40145 int result;
- 40146
- 40147 va_start(argp, name);
- 40148
- 40149 /* The following cast of argp is not portable, as for execl(). */
- 40150 p = (char **) argp;
- 40151 while (*p++ != NIL_PTR)
- 40152 ; /* null statement */
- 40153 result = execve(name, (char **) argp, (char **) *p);
- 40154 va_end(argp);
- .Ep 390 src/lib/posix/_exec.c
- 40155 return(result);
- 40156 }
-
-
- 40159 PUBLIC int execv(name, argv)
- 40160 _CONST char *name;
- 40161 char * _CONST argv[];
- 40162 {
- 40163 return(execve(name, argv, environ));
- 40164 }
-
-
- 40167 PUBLIC int execve(path, argv, envp)
- 40168 _CONST char *path; /* pointer to name of file to be executed */
- 40169 char * _CONST argv[]; /* pointer to argument array */
- 40170 char * _CONST envp[]; /* pointer to environment */
- 40171 {
- 40172 int i, j;
- 40173
- 40174 /* Count the argument pointers and environment pointers. */
- 40175 i = 0;
- 40176 if (argv != NULL)
- 40177 {
- 40178 while (argv[i] != NULL) i++;
- 40179 }
- 40180 j = 0;
- 40181 if (envp != NULL)
- 40182 {
- 40183 while (envp[j] != NULL) j++;
- 40184 }
- 40185
- 40186 return(__execve(path, argv, envp, i, j));
- 40187 }
-
-
- 40190 PUBLIC int __execve(path, argv, envp, nargs, nenvps)
- 40191 _CONST char *path; /* pointer to name of file to be executed */
- 40192 char * _CONST argv[]; /* pointer to argument array */
- 40193 char * _CONST envp[]; /* pointer to environment */
- 40194 int nargs; /* number of args */
- 40195 int nenvps; /* number of environment strings */
- 40196 {
- 40197 /* This is split off from execve to be called from execvp, so execvp does not
- 40198 * have to allocate up to ARG_MAX bytes just to prepend "sh" to the arg array.
- 40199 */
- 40200
- 40201 char *hp, **ap, *p;
- 40202 int i, stackbytes, npointers, overflow, temp;
- 40203 char *stack;
- 40204 message m;
- 40205
- 40206 /* Decide how big a stack is needed. Be paranoid about overflow. */
- 40207 overflow = FALSE;
- 40208 npointers = 1 + nargs + 1 + nenvps + 1; /* 1's for argc and NULLs */
- 40209 stackbytes = nargs + nenvps; /* 1 byte for each null in strings */
- 40210 if (nargs < 0 || nenvps < 0 || stackbytes < nargs || npointers < stackbytes)
- 40211 overflow = TRUE;
- 40212 for (i = PTRSIZE; i != 0; i--) {
- 40213 temp = stackbytes + npointers;
- 40214 if (temp < stackbytes) overflow = TRUE;
- .Op 391 src/lib/posix/_exec.c
- 40215 stackbytes = temp;
- 40216 }
- 40217 ap = (char **) argv;
- 40218 for (i = 0; i < nargs; i++) {
- 40219 temp = stackbytes + strlen(*ap++);
- 40220 if (temp < stackbytes) overflow = TRUE;
- 40221 stackbytes = temp;
- 40222 }
- 40223 ap = (char **) envp;
- 40224 for (i = 0; i < nenvps; i++) {
- 40225 temp = stackbytes + strlen(*ap++);
- 40226 if (temp < stackbytes) overflow = TRUE;
- 40227 stackbytes = temp;
- 40228 }
- 40229 temp = stackbytes + PTRSIZE - 1;
- 40230 if (temp < stackbytes) overflow = TRUE;
- 40231 stackbytes = (temp / PTRSIZE) * PTRSIZE;
- 40232
- 40233 /* Check for overflow before committing sbrk. */
- 40234 if (overflow) {
- 40235 errno = E2BIG;
- 40236 return(-1);
- 40237 }
- 40238
- 40239 /* Allocate the stack. */
- 40240 stack = sbrk(stackbytes);
- 40241 if (stack == (char *) -1) {
- 40242 errno = E2BIG;
- 40243 return(-1);
- 40244 }
- 40245
- 40246 /* Prepare the stack vector and argc. */
- 40247 ap = (char **) stack;
- 40248 hp = &stack[npointers * PTRSIZE];
- 40249 *ap++ = (char *) nargs;
- 40250
- 40251 /* Prepare the argument pointers and strings. */
- 40252 for (i = 0; i < nargs; i++) {
- 40253 *ap++ = (char *) (hp - stack);
- 40254 p = *argv++;
- 40255 while ( (*hp++ = *p++) != 0)
- 40256 ;
- 40257 }
- 40258 *ap++ = (char *) NULL;
- 40259
- 40260 /* Prepare the environment pointers and strings. */
- 40261 for (i = 0; i < nenvps; i++) {
- 40262 *ap++ = (char *) (hp - stack);
- 40263 p = *envp++;
- 40264 while ( (*hp++ = *p++) != 0)
- 40265 ;
- 40266 }
- 40267 *ap++ = (char *) NULL;
- 40268
- 40269 /* Do the real work. */
- 40270 m.m1_i1 = strlen(path) + 1;
- 40271 m.m1_i2 = stackbytes;
- 40272 m.m1_p1 = (char *) path;
- 40273 m.m1_p2 = stack;
- 40274 (void) _syscall(MM, EXEC, &m);
- .Ep 392 src/lib/posix/_exec.c
- 40275
- 40276 /* The exec failed. */
- 40277 sbrk(-stackbytes);
- 40278 return(m.m_type);
- 40279 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_execn.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 40300 #include <lib.h>
- 40301 #include <string.h>
- 40302
- 40303 #define PTRSIZE sizeof(char *)
- 40304 _PROTOTYPE( int _execn, (char * name));
- 40305
- 40306 PUBLIC int _execn(name)
- 40307 char *name; /* pointer to file to be exec'd */
- 40308 {
- 40309 /* Special version used when there are no args and no environment. This call
- 40310 * is principally used by INIT, to avoid having to allocate ARG_MAX.
- 40311 */
- 40312
- 40313 PRIVATE char stack[3 * PTRSIZE];
- 40314 message m;
- 40315
- 40316 m.m1_i1 = strlen(name) + 1;
- 40317 m.m1_i2 = sizeof(stack);
- 40318 m.m1_p1 = name;
- 40319 m.m1_p2 = stack;
- 40320 (void) _syscall(MM, EXEC, &m);
- 40321 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_fcntl.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 40400 #include <lib.h>
- 40401 #define fcntl _fcntl
- 40402 #include <fcntl.h>
- 40403 #include <stdarg.h>
- 40404
- 40405 #if _ANSI
- 40406 PUBLIC int fcntl(int fd, int cmd, ...)
- 40407 #else
- 40408 PUBLIC int fcntl(fd, cmd)
- 40409 int fd;
- 40410 int cmd;
- 40411 #endif
- 40412 {
- 40413 va_list argp;
- 40414 message m;
- .Op 393 src/lib/posix/_fcntl.c
- 40415
- 40416 va_start(argp, cmd);
- 40417
- 40418 /* Set up for the sensible case where there is no variable parameter. This
- 40419 * covers F_GETFD, F_GETFL and invalid commands.
- 40420 */
- 40421 m.m1_i3 = 0;
- 40422 m.m1_p1 = NIL_PTR;
- 40423
- 40424 /* Adjust for the stupid cases. */
- 40425 switch(cmd) {
- 40426 case F_DUPFD:
- 40427 case F_SETFD:
- 40428 case F_SETFL:
- 40429 m.m1_i3 = va_arg(argp, int);
- 40430 break;
- 40431 case F_GETLK:
- 40432 case F_SETLK:
- 40433 case F_SETLKW:
- 40434 m.m1_p1 = (char *) va_arg(argp, struct flock *);
- 40435 break;
- 40436 }
- 40437
- 40438 /* Clean up and make the system call. */
- 40439 va_end(argp);
- 40440 m.m1_i1 = fd;
- 40441 m.m1_i2 = cmd;
- 40442 return(_syscall(FS, FCNTL, &m));
- 40443 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_fork.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 40500 #include <lib.h>
- 40501 #define fork _fork
- 40502 #include <unistd.h>
- 40503
- 40504 PUBLIC pid_t fork()
- 40505 {
- 40506 message m;
- 40507
- 40508 return(_syscall(MM, FORK, &m));
- 40509 }
- .Ep 394 src/lib/posix/_fpathconf.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_fpathconf.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 40600 /* POSIX fpathconf (Sec. 5.7.1) Author: Andy Tanenbaum */
- 40601
- 40602 #include <lib.h>
- 40603 #define fstat _fstat
- 40604 #define fpathconf _fpathconf
- 40605 #include <sys/stat.h>
- 40606 #include <errno.h>
- 40607 #include <limits.h>
- 40608 #include <unistd.h>
- 40609 #include <termios.h>
- 40610
- 40611 PUBLIC long fpathconf(fd, name)
- 40612 int fd; /* file descriptor being interrogated */
- 40613 int name; /* property being inspected */
- 40614 {
- 40615 /* POSIX allows some of the values in <limits.h> to be increased at
- 40616 * run time. The pathconf and fpathconf functions allow these values
- 40617 * to be checked at run time. MINIX does not use this facility.
- 40618 * The run-time limits are those given in <limits.h>.
- 40619 */
- 40620
- 40621 struct stat stbuf;
- 40622
- 40623 switch(name) {
- 40624 case _PC_LINK_MAX:
- 40625 /* Fstat the file. If that fails, return -1. */
- 40626 if (fstat(fd, &stbuf) != 0) return(-1);
- 40627 if (S_ISDIR(stbuf.st_mode))
- 40628 return(1L); /* no links to directories */
- 40629 else
- 40630 return( (long) LINK_MAX);
- 40631
- 40632 case _PC_MAX_CANON:
- 40633 return( (long) MAX_CANON);
- 40634
- 40635 case _PC_MAX_INPUT:
- 40636 return( (long) MAX_INPUT);
- 40637
- 40638 case _PC_NAME_MAX:
- 40639 return( (long) NAME_MAX);
- 40640
- 40641 case _PC_PATH_MAX:
- 40642 return( (long) PATH_MAX);
- 40643
- 40644 case _PC_PIPE_BUF:
- 40645 return( (long) PIPE_BUF);
- 40646
- 40647 case _PC_CHOWN_RESTRICTED:
- 40648 return( (long) _POSIX_CHOWN_RESTRICTED);
- 40649
- 40650 case _PC_NO_TRUNC:
- 40651 return( (long) _POSIX_NO_TRUNC);
- 40652
- 40653 case _PC_VDISABLE:
- 40654 return( (long) _POSIX_VDISABLE);
- .Op 395 src/lib/posix/_fpathconf.c
- 40655
- 40656 default:
- 40657 errno = EINVAL;
- 40658 return(-1);
- 40659 }
- 40660 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_fstat.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 40700 #include <lib.h>
- 40701 #define fstat _fstat
- 40702 #include <sys/stat.h>
- 40703
- 40704 PUBLIC int fstat(fd, buffer)
- 40705 int fd;
- 40706 struct stat *buffer;
- 40707 {
- 40708 message m;
- 40709
- 40710 m.m1_i1 = fd;
- 40711 m.m1_p1 = (char *) buffer;
- 40712 return(_syscall(FS, FSTAT, &m));
- 40713 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_getcwd.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 40800 /* getcwd() - get the name of the current working directory.
- 40801 * Author: Kees J. Bot
- 40802 * 30 Apr 1989
- 40803 */
- 40804 #define nil 0
- 40805 #define chdir _chdir
- 40806 #define closedir _closedir
- 40807 #define getcwd _getcwd
- 40808 #define opendir _opendir
- 40809 #define readdir _readdir
- 40810 #define rewinddir _rewinddir
- 40811 #define stat _stat
- 40812 #include <sys/types.h>
- 40813 #include <sys/stat.h>
- 40814 #include <errno.h>
- 40815 #include <unistd.h>
- 40816 #include <dirent.h>
- 40817 #include <limits.h>
- 40818 #include <string.h>
- 40819
- 40820 static int addpath(const char *path, char **ap, const char *entry)
- 40821 /* Add the name of a directory entry at the front of the path being built.
- 40822 * Note that the result always starts with a slash.
- 40823 */
- 40824 {
- .Ep 396 src/lib/posix/_getcwd.c
- 40825 const char *e= entry;
- 40826 char *p= *ap;
- 40827
- 40828 while (*e != 0) e++;
- 40829
- 40830 while (e > entry && p > path) *--p = *--e;
- 40831
- 40832 if (p == path) return -1;
- 40833 *--p = '/';
- 40834 *ap= p;
- 40835 return 0;
- 40836 }
-
- 40838 static int recover(char *p)
- 40839 /* Undo all those chdir("..")'s that have been recorded by addpath. This
- 40840 * has to be done entry by entry, because the whole pathname may be too long.
- 40841 */
- 40842 {
- 40843 int e= errno, slash;
- 40844 char *p0;
- 40845
- 40846 while (*p != 0) {
- 40847 p0= ++p;
- 40848
- 40849 do p++; while (*p != 0 && *p != '/');
- 40850 slash= *p; *p= 0;
- 40851
- 40852 if (chdir(p0) < 0) return -1;
- 40853 *p= slash;
- 40854 }
- 40855 errno= e;
- 40856 return 0;
- 40857 }
-
- 40859 char *getcwd(char *path, size_t size)
- 40860 {
- 40861 struct stat above, current, tmp;
- 40862 struct dirent *entry;
- 40863 DIR *d;
- 40864 char *p, *up, *dotdot;
- 40865 int cycle;
- 40866
- 40867 if (path == nil || size <= 2) { errno= EINVAL; return nil; }
- 40868
- 40869 p= path + size;
- 40870 *--p = 0;
- 40871
- 40872 if (stat(".", ¤t) < 0) return nil;
- 40873
- 40874 while (1) {
- 40875 dotdot= "..";
- 40876 if (stat(dotdot, &above) < 0) { recover(p); return nil; }
- 40877
- 40878 if (above.st_dev == current.st_dev
- 40879 && above.st_ino == current.st_ino)
- 40880 break; /* Root dir found */
- 40881
- 40882 if ((d= opendir(dotdot)) == nil) { recover(p); return nil; }
- 40883
- 40884 /* Cycle is 0 for a simple inode nr search, or 1 for a search
- .Op 397 src/lib/posix/_getcwd.c
- 40885 * for inode *and* device nr.
- 40886 */
- 40887 cycle= above.st_dev == current.st_dev ? 0 : 1;
- 40888
- 40889 do {
- 40890 char name[3 + NAME_MAX + 1];
- 40891
- 40892 tmp.st_ino= 0;
- 40893 if ((entry= readdir(d)) == nil) {
- 40894 switch (++cycle) {
- 40895 case 1:
- 40896 rewinddir(d);
- 40897 continue;
- 40898 case 2:
- 40899 closedir(d);
- 40900 errno= ENOENT;
- 40901 recover(p);
- 40902 return nil;
- 40903 }
- 40904 }
- 40905 if (strcmp(entry->d_name, ".") == 0) continue;
- 40906 if (strcmp(entry->d_name, "..") == 0) continue;
- 40907
- 40908 switch (cycle) {
- 40909 case 0:
- 40910 /* Simple test on inode nr. */
- 40911 if (entry->d_ino != current.st_ino) continue;
- 40912 /*FALL THROUGH*/
- 40913
- 40914 case 1:
- 40915 /* Current is mounted. */
- 40916 strcpy(name, "../");
- 40917 strcpy(name+3, entry->d_name);
- 40918 if (stat(name, &tmp) < 0) continue;
- 40919 break;
- 40920 }
- 40921 } while (tmp.st_ino != current.st_ino
- 40922 || tmp.st_dev != current.st_dev);
- 40923
- 40924 up= p;
- 40925 if (addpath(path, &up, entry->d_name) < 0) {
- 40926 closedir(d);
- 40927 errno = ERANGE;
- 40928 recover(p);
- 40929 return nil;
- 40930 }
- 40931 closedir(d);
- 40932
- 40933 if (chdir(dotdot) < 0) { recover(p); return nil; }
- 40934 p= up;
- 40935
- 40936 current= above;
- 40937 }
- 40938 if (recover(p) < 0) return nil; /* Undo all those chdir("..")'s. */
- 40939 if (*p == 0) *--p = '/'; /* Cwd is "/" if nothing added */
- 40940 if (p > path) strcpy(path, p); /* Move string to start of path. */
- 40941 return path;
- 40942 }
- .Ep 398 src/lib/posix/_getegid.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_getegid.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 41000 #include <lib.h>
- 41001 #define getegid _getegid
- 41002 #include <unistd.h>
- 41003
- 41004 PUBLIC gid_t getegid()
- 41005 {
- 41006 message m;
- 41007
- 41008 /* POSIX says that this function is always successful and that no
- 41009 * return value is reserved to indicate an error. Minix syscalls
- 41010 * are not always successful and Minix returns the unreserved value
- 41011 * (gid_t) -1 when there is an error.
- 41012 */
- 41013 if (_syscall(MM, GETGID, &m) < 0) return ( (gid_t) -1);
- 41014 return( (gid_t) m.m2_i1);
- 41015 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_geteuid.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 41100 #include <lib.h>
- 41101 #define geteuid _geteuid
- 41102 #include <unistd.h>
- 41103
- 41104 PUBLIC uid_t geteuid()
- 41105 {
- 41106 message m;
- 41107
- 41108 /* POSIX says that this function is always successful and that no
- 41109 * return value is reserved to indicate an error. Minix syscalls
- 41110 * are not always successful and Minix returns the unreserved value
- 41111 * (uid_t) -1 when there is an error.
- 41112 */
- 41113 if (_syscall(MM, GETUID, &m) < 0) return ( (uid_t) -1);
- 41114 return( (uid_t) m.m2_i1);
- 41115 }
- .Op 399 src/lib/posix/_getgid.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_getgid.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 41200 #include <lib.h>
- 41201 #define getgid _getgid
- 41202 #include <unistd.h>
- 41203
- 41204 PUBLIC gid_t getgid()
- 41205 {
- 41206 message m;
- 41207
- 41208 return( (gid_t) _syscall(MM, GETGID, &m));
- 41209 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_getgroups.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 41300 /* getgroups.c POSIX 4.2.3
- 41301 * int getgroups(gidsetsize, grouplist);
- 41302 *
- 41303 * This call relates to suplementary group ids, which are not
- 41304 * supported in MINIX.
- 41305 */
- 41306
- 41307 #include <lib.h>
- 41308 #define getgroups _getgroups
- 41309 #include <unistd.h>
- 41310 #include <time.h>
- 41311
- 41312 PUBLIC int getgroups(gidsetsize, grouplist)
- 41313 int gidsetsize;
- 41314 gid_t grouplist[];
- 41315 {
- 41316 return(0);
- 41317 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_getpgrp.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 41400 #include <lib.h>
- 41401 #define getpgrp _getpgrp
- 41402 #include <unistd.h>
- 41403
- 41404 PUBLIC pid_t getpgrp()
- 41405 {
- 41406 message m;
- 41407
- 41408 return(_syscall(MM, GETPGRP, &m));
- 41409 }
- .Ep 400 src/lib/posix/_getpid.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_getpid.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 41500 #include <lib.h>
- 41501 #define getpid _getpid
- 41502 #include <unistd.h>
- 41503
- 41504 PUBLIC pid_t getpid()
- 41505 {
- 41506 message m;
- 41507
- 41508 return(_syscall(MM, GETPID, &m));
- 41509 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_getppid.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 41600 #include <lib.h>
- 41601 #define getppid _getppid
- 41602 #include <unistd.h>
- 41603
- 41604 PUBLIC pid_t getppid()
- 41605 {
- 41606 message m;
- 41607
- 41608 /* POSIX says that this function is always successful and that no
- 41609 * return value is reserved to indicate an error. Minix syscalls
- 41610 * are not always successful and Minix returns the reserved value
- 41611 * (pid_t) -1 when there is an error.
- 41612 */
- 41613 if (_syscall(MM, GETPID, &m) < 0) return ( (pid_t) -1);
- 41614 return( (pid_t) m.m2_i1);
- 41615 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_getuid.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 41700 #include <lib.h>
- 41701 #define getuid _getuid
- 41702 #include <unistd.h>
- 41703
- 41704 PUBLIC uid_t getuid()
- 41705 {
- 41706 message m;
- 41707
- 41708 return( (uid_t) _syscall(MM, GETUID, &m));
- 41709 }
- .Op 401 src/lib/posix/_ioctl.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_ioctl.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 41800 #include <lib.h>
- 41801 #define ioctl _ioctl
- 41802 #include <minix/com.h>
- 41803 #include <sys/ioctl.h>
- 41804
- 41805 PUBLIC int ioctl(fd, request, data)
- 41806 int fd;
- 41807 int request;
- 41808 void *data;
- 41809 {
- 41810 message m;
- 41811
- 41812 m.TTY_LINE = fd;
- 41813 m.TTY_REQUEST = request;
- 41814 m.ADDRESS = (char *) data;
- 41815 return(_syscall(FS, IOCTL, &m));
- 41816 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_isatty.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 41900 #include <lib.h>
- 41901 #define isatty _isatty
- 41902 #define tcgetattr _tcgetattr
- 41903 #include <termios.h>
- 41904 #include <unistd.h>
- 41905
- 41906 PUBLIC int isatty(fd)
- 41907 int fd;
- 41908 {
- 41909 struct termios dummy;
- 41910
- 41911 return(tcgetattr(fd, &dummy) == 0);
- 41912 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_kill.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 42000 #include <lib.h>
- 42001 #define kill _kill
- 42002 #include <signal.h>
- 42003
- 42004 PUBLIC int kill(proc, sig)
- 42005 int proc; /* which process is to be sent the signal */
- 42006 int sig; /* signal number */
- 42007 {
- 42008 message m;
- 42009
- .Ep 402 src/lib/posix/_kill.c
- 42010 m.m1_i1 = proc;
- 42011 m.m1_i2 = sig;
- 42012 return(_syscall(MM, KILL, &m));
- 42013 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_link.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 42100 #include <lib.h>
- 42101 #define link _link
- 42102 #include <string.h>
- 42103 #include <unistd.h>
- 42104
- 42105 PUBLIC int link(name, name2)
- 42106 _CONST char *name, *name2;
- 42107 {
- 42108 message m;
- 42109
- 42110 m.m1_i1 = strlen(name) + 1;
- 42111 m.m1_i2 = strlen(name2) + 1;
- 42112 m.m1_p1 = (char *) name;
- 42113 m.m1_p2 = (char *) name2;
- 42114 return(_syscall(FS, LINK, &m));
- 42115 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_lseek.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 42200 #include <lib.h>
- 42201 #define lseek _lseek
- 42202 #include <unistd.h>
- 42203
- 42204 PUBLIC off_t lseek(fd, offset, whence)
- 42205 int fd;
- 42206 off_t offset;
- 42207 int whence;
- 42208 {
- 42209 message m;
- 42210
- 42211 m.m2_i1 = fd;
- 42212 m.m2_l1 = offset;
- 42213 m.m2_i2 = whence;
- 42214 if (_syscall(FS, LSEEK, &m) < 0) return( (off_t) -1);
- 42215 return( (off_t) m.m2_l1);
- 42216 }
- .Op 403 src/lib/posix/_mkdir.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_mkdir.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 42300 #include <lib.h>
- 42301 #define mkdir _mkdir
- 42302 #include <sys/stat.h>
- 42303 #include <string.h>
- 42304
- 42305 PUBLIC int mkdir(name, mode)
- 42306 _CONST char *name;
- 42307 Mode_t mode;
- 42308 {
- 42309 message m;
- 42310
- 42311 m.m1_i1 = strlen(name) + 1;
- 42312 m.m1_i2 = mode;
- 42313 m.m1_p1 = (char *) name;
- 42314 return(_syscall(FS, MKDIR, &m));
- 42315 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_mkfifo.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 42400 #include <lib.h>
- 42401 #define mkfifo _mkfifo
- 42402 #define mknod _mknod
- 42403 #include <sys/stat.h>
- 42404 #include <unistd.h>
- 42405
- 42406 PUBLIC int mkfifo(name, mode)
- 42407 _CONST char *name;
- 42408 Mode_t mode;
- 42409 {
- 42410 return mknod(name, mode | S_IFIFO, (Dev_t) 0);
- 42411 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_mknod.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 42500 #include <lib.h>
- 42501 #define mknod _mknod
- 42502 #include <string.h>
- 42503 #include <stdlib.h>
- 42504 #include <unistd.h>
- 42505
- 42506 PUBLIC int mknod(name, mode, dev)
- 42507 _CONST char *name;
- 42508 Mode_t mode;
- 42509 Dev_t dev;
- .Ep 404 src/lib/posix/_mknod.c
- 42510 {
- 42511 message m;
- 42512
- 42513 m.m1_i1 = strlen(name) + 1;
- 42514 m.m1_i2 = mode;
- 42515 m.m1_i3 = dev;
- 42516 m.m1_p1 = (char *) name;
- 42517 m.m1_p2 = (char *) ((int) 0); /* obsolete size field */
- 42518 return(_syscall(FS, MKNOD, &m));
- 42519 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_mktemp.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 42600 /* mktemp - make a name for a temporary file */
- 42601
- 42602 #include <lib.h>
- 42603 #define access _access
- 42604 #define getpid _getpid
- 42605 #define mktemp _mktemp
- 42606 #include <unistd.h>
- 42607
- 42608 PUBLIC char *mktemp(template)
- 42609 char *template;
- 42610 {
- 42611 register int k;
- 42612 register char *p;
- 42613 register pid_t pid;
- 42614
- 42615 pid = getpid(); /* get process id as semi-unique number */
- 42616 p = template;
- 42617 while (*p != 0) p++; /* find end of string */
- 42618
- 42619 /* Replace XXXXXX at end of template with a letter, then as many of the
- 42620 * trailing digits of the pid as fit.
- 42621 */
- 42622 while (*--p == 'X') {
- 42623 *p = '0' + (pid % 10);
- 42624 pid /= 10;
- 42625 }
- 42626 if (*++p != 0) {
- 42627 for (k = 'a'; k <= 'z'; k++) {
- 42628 *p = k;
- 42629 if (access(template, F_OK) < 0) return(template);
- 42630 }
- 42631 }
- 42632 return("/");
- 42633 }
- .Op 405 src/lib/posix/_mount.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_mount.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 42700 #include <lib.h>
- 42701 #define mount _mount
- 42702 #include <string.h>
- 42703 #include <unistd.h>
- 42704
- 42705 PUBLIC int mount(special, name, rwflag)
- 42706 char *name, *special;
- 42707 int rwflag;
- 42708 {
- 42709 message m;
- 42710
- 42711 m.m1_i1 = strlen(special) + 1;
- 42712 m.m1_i2 = strlen(name) + 1;
- 42713 m.m1_i3 = rwflag;
- 42714 m.m1_p1 = special;
- 42715 m.m1_p2 = name;
- 42716 return(_syscall(FS, MOUNT, &m));
- 42717 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_open.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 42800 #include <lib.h>
- 42801 #define open _open
- 42802 #include <fcntl.h>
- 42803 #include <stdarg.h>
- 42804 #include <string.h>
- 42805
- 42806 #if _ANSI
- 42807 PUBLIC int open(const char *name, int flags, ...)
- 42808 #else
- 42809 PUBLIC int open(name, flags)
- 42810 _CONST char *name;
- 42811 int flags;
- 42812 #endif
- 42813 {
- 42814 va_list argp;
- 42815 message m;
- 42816
- 42817 va_start(argp, flags);
- 42818 if (flags & O_CREAT) {
- 42819 m.m1_i1 = strlen(name) + 1;
- 42820 m.m1_i2 = flags;
- 42821 m.m1_i3 = va_arg(argp, Mode_t);
- 42822 m.m1_p1 = (char *) name;
- 42823 } else {
- 42824 _loadname(name, &m);
- 42825 m.m3_i2 = flags;
- 42826 }
- 42827 va_end(argp);
- 42828 return (_syscall(FS, OPEN, &m));
- 42829 }
- .Ep 406 src/lib/posix/_opendir.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_opendir.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 42900 /* opendir() Author: Kees J. Bot
- 42901 * 24 Apr 1989
- 42902 */
- 42903 #define nil 0
- 42904 #include <lib.h>
- 42905 #define close _close
- 42906 #define fcntl _fcntl
- 42907 #define fstat _fstat
- 42908 #define open _open
- 42909 #define opendir _opendir
- 42910 #define stat _stat
- 42911 #include <sys/types.h>
- 42912 #include <sys/stat.h>
- 42913 #include <dirent.h>
- 42914 #include <unistd.h>
- 42915 #include <stdlib.h>
- 42916 #include <fcntl.h>
- 42917 #include <errno.h>
- 42918
- 42919 DIR *opendir(const char *name)
- 42920 /* Open a directory for reading. */
- 42921 {
- 42922 int d, f;
- 42923 DIR *dp;
- 42924 struct stat st;
- 42925
- 42926 /* Only read directories. */
- 42927 if (stat(name, &st) < 0) return nil;
- 42928 if (!S_ISDIR(st.st_mode)) { errno= ENOTDIR; return nil; }
- 42929
- 42930 if ((d= open(name, O_RDONLY | O_NONBLOCK)) < 0) return nil;
- 42931
- 42932 /* Check the type again, mark close-on-exec, get a buffer. */
- 42933 if (fstat(d, &st) < 0
- 42934 || (errno= ENOTDIR, !S_ISDIR(st.st_mode))
- 42935 || (f= fcntl(d, F_GETFD)) < 0
- 42936 || fcntl(d, F_SETFD, f | FD_CLOEXEC) < 0
- 42937 || (dp= (DIR *) malloc(sizeof(*dp))) == nil
- 42938 ) {
- 42939 int err= errno;
- 42940 (void) close(d);
- 42941 errno= err;
- 42942 return nil;
- 42943 }
- 42944
- 42945 dp->_fd= d;
- 42946 dp->_v7= -1;
- 42947 dp->_count= 0;
- 42948 dp->_pos= 0;
- 42949
- 42950 return dp;
- 42951 }
- .Op 407 src/lib/posix/_pathconf.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_pathconf.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 43000 /* POSIX pathconf (Sec. 5.7.1) Author: Andy Tanenbaum */
- 43001
- 43002 #include <lib.h>
- 43003 #define close _close
- 43004 #define open _open
- 43005 #define pathconf _pathconf
- 43006 #include <fcntl.h>
- 43007 #include <errno.h>
- 43008 #include <unistd.h>
- 43009
- 43010 PUBLIC long pathconf(path, name)
- 43011 _CONST char *path; /* name of file being interrogated */
- 43012 int name; /* property being inspected */
- 43013 {
- 43014 /* POSIX allows some of the values in <limits.h> to be increased at
- 43015 * run time. The pathconf and fpathconf functions allow these values
- 43016 * to be checked at run time. MINIX does not use this facility.
- 43017 * The run-time limits are those given in <limits.h>.
- 43018 */
- 43019
- 43020 int fd;
- 43021 long val;
- 43022
- 43023 if ( (fd = open(path, O_RDONLY)) < 0) return(-1L);
- 43024 val = fpathconf(fd, name);
- 43025 close(fd);
- 43026 return(val);
- 43027 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_pause.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 43100 #include <lib.h>
- 43101 #define pause _pause
- 43102 #include <unistd.h>
- 43103
- 43104 PUBLIC int pause()
- 43105 {
- 43106 message m;
- 43107
- 43108 return(_syscall(MM, PAUSE, &m));
- 43109 }
- .Ep 408 src/lib/posix/_pipe.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_pipe.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 43200 #include <lib.h>
- 43201 #define pipe _pipe
- 43202 #include <unistd.h>
- 43203
- 43204 PUBLIC int pipe(fild)
- 43205 int fild[2];
- 43206 {
- 43207 message m;
- 43208
- 43209 if (_syscall(FS, PIPE, &m) < 0) return(-1);
- 43210 fild[0] = m.m1_i1;
- 43211 fild[1] = m.m1_i2;
- 43212 return(0);
- 43213 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_ptrace.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 43300 #include <lib.h>
- 43301 #define ptrace _ptrace
- 43302 #include <unistd.h>
- 43303
- 43304 PUBLIC long ptrace(req, pid, addr, data)
- 43305 int req;
- 43306 pid_t pid;
- 43307 long addr;
- 43308 long data;
- 43309 {
- 43310 message m;
- 43311
- 43312 m.m2_i1 = pid;
- 43313 m.m2_i2 = req;
- 43314 m.m2_l1 = addr;
- 43315 m.m2_l2 = data;
- 43316 if (_syscall(MM, PTRACE, &m) < 0) return(-1);
- 43317
- 43318 /* There was no error, but -1 is a legal return value. Clear errno if
- 43319 * necessary to distinguish this case. _syscall has set errno to nonzero
- 43320 * for the error case.
- 43321 */
- 43322 if (m.m2_l2 == -1) errno = 0;
- 43323 return(m.m2_l2);
- 43324 }
- .Op 409 src/lib/posix/_read.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_read.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 43400 #include <lib.h>
- 43401 #define read _read
- 43402 #include <unistd.h>
- 43403
- 43404 PUBLIC ssize_t read(fd, buffer, nbytes)
- 43405 int fd;
- 43406 void *buffer;
- 43407 size_t nbytes;
- 43408 {
- 43409 message m;
- 43410
- 43411 m.m1_i1 = fd;
- 43412 m.m1_i2 = nbytes;
- 43413 m.m1_p1 = (char *) buffer;
- 43414 return(_syscall(FS, READ, &m));
- 43415 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_readdir.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 43500 /* readdir() Author: Kees J. Bot
- 43501 * 24 Apr 1989
- 43502 */
- 43503 #define nil 0
- 43504 #include <lib.h>
- 43505 #define read _read
- 43506 #define readdir _readdir
- 43507 #include <sys/types.h>
- 43508 #include <sys/stat.h>
- 43509 #include <dirent.h>
- 43510 #include <unistd.h>
- 43511 #include <stdlib.h>
- 43512 #include <fcntl.h>
- 43513 #include <limits.h>
- 43514 #include <errno.h>
- 43515 #include <string.h>
- 43516
- 43517 #define v7ent(p) ((struct _v7_direct *) (p))
- 43518
- 43519 struct dirent *readdir(DIR *dp)
- 43520 /* Return the next entry in a directory. Handle V7 and FLEX format dirs. */
- 43521 {
- 43522 struct dirent *e;
- 43523
- 43524 if (dp == nil) { errno= EBADF; return nil; }
- 43525
- 43526 do {
- 43527 if (dp->_count <= 0) {
- 43528 /* Read the next directory block. */
- 43529 dp->_count= read(dp->_fd, dp->_buf, sizeof(dp->_buf));
- .Ep 410 src/lib/posix/_readdir.c
- 43530 if (dp->_count <= 0) return nil;
- 43531
- 43532 dp->_count/= sizeof(dp->_buf[0]);
- 43533 dp->_ptr= dp->_buf;
- 43534
- 43535 /* Extent is zero of the first flex entry. */
- 43536 if (dp->_v7 == (char)-1) dp->_v7= dp->_buf[0].d_extent;
- 43537 }
- 43538
- 43539 if (!dp->_v7) {
- 43540 /* FLEX. */
- 43541 e= (struct dirent *) dp->_ptr;
- 43542 } else {
- 43543 /* V7: transform to FLEX. */
- 43544 e= (struct dirent *) dp->_v7f;
- 43545 e->d_ino= v7ent(dp->_ptr)->d_ino;
- 43546 e->d_extent= 1;
- 43547 memcpy(e->d_name, v7ent(dp->_ptr)->d_name, 14);
- 43548 e->d_name[14]= 0;
- 43549 }
- 43550
- 43551 dp->_ptr+= 1 + e->d_extent;
- 43552 dp->_count-= 1 + e->d_extent;
- 43553 dp->_pos+= (1 + e->d_extent) * sizeof(*dp->_ptr);
- 43554
- 43555 } while (e->d_ino == 0);
- 43556 return e;
- 43557 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_rename.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 43600 #include <lib.h>
- 43601 #define rename _rename
- 43602 #include <string.h>
- 43603 #include <stdio.h>
- 43604
- 43605 PUBLIC int rename(name, name2)
- 43606 _CONST char *name, *name2;
- 43607 {
- 43608 message m;
- 43609
- 43610 m.m1_i1 = strlen(name) + 1;
- 43611 m.m1_i2 = strlen(name2) + 1;
- 43612 m.m1_p1 = (char *) name;
- 43613 m.m1_p2 = (char *) name2;
- 43614 return(_syscall(FS, RENAME, &m));
- 43615 }
- .Op 411 src/lib/posix/_rewinddir.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_rewinddir.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 43700 /* rewinddir() Author: Kees J. Bot
- 43701 * 24 Apr 1989
- 43702 */
- 43703 #define nil 0
- 43704 #include <lib.h>
- 43705 #define rewinddir _rewinddir
- 43706 #define seekdir _seekdir
- 43707 #include <sys/types.h>
- 43708 #include <dirent.h>
- 43709
- 43710 void rewinddir(DIR *dp)
- 43711 {
- 43712 (void) seekdir(dp, 0);
- 43713 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_rmdir.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 43800 #include <lib.h>
- 43801 #define rmdir _rmdir
- 43802 #include <unistd.h>
- 43803
- 43804 PUBLIC int rmdir(name)
- 43805 _CONST char *name;
- 43806 {
- 43807 message m;
- 43808
- 43809 _loadname(name, &m);
- 43810 return(_syscall(FS, RMDIR, &m));
- 43811 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_setgid.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 43900 #include <lib.h>
- 43901 #define setgid _setgid
- 43902 #include <unistd.h>
- 43903
- 43904 PUBLIC int setgid(grp)
- 43905 gid_t grp;
- 43906 {
- 43907 message m;
- 43908
- 43909 m.m1_i1 = (int) grp;
- 43910 return(_syscall(MM, SETGID, &m));
- 43911 }
- .Ep 412 src/lib/posix/_setsid.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_setsid.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 44000 #include <lib.h>
- 44001 #define setsid _setsid
- 44002 #include <unistd.h>
- 44003
- 44004 PUBLIC pid_t setsid()
- 44005 {
- 44006 message m;
- 44007
- 44008 return(_syscall(MM, SETSID, &m));
- 44009 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_setuid.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 44100 #include <lib.h>
- 44101 #define setuid _setuid
- 44102 #include <unistd.h>
- 44103
- 44104 PUBLIC int setuid(usr)
- 44105 Uid_t usr;
- 44106 {
- 44107 message m;
- 44108
- 44109 m.m1_i1 = usr;
- 44110 return(_syscall(MM, SETUID, &m));
- 44111 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_sigaction.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 44200 #include <lib.h>
- 44201 #define sigaction _sigaction
- 44202 #include <sys/sigcontext.h>
- 44203 #include <signal.h>
- 44204
- 44205 _PROTOTYPE(int __sigreturn, (void));
- 44206
- 44207 PUBLIC int sigaction(sig, act, oact)
- 44208 int sig;
- 44209 _CONST struct sigaction *act;
- 44210 struct sigaction *oact;
- 44211 {
- 44212 message m;
- 44213
- 44214 m.m1_i2 = sig;
- .Op 413 src/lib/posix/_sigaction.c
- 44215
- 44216 /* XXX - yet more type puns because message struct is short of types. */
- 44217 m.m1_p1 = (char *) act;
- 44218 m.m1_p2 = (char *) oact;
- 44219 m.m1_p3 = (char *) __sigreturn;
- 44220
- 44221 return(_syscall(MM, SIGACTION, &m));
- 44222 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_sigpending.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 44300 #include <lib.h>
- 44301 #define sigpending _sigpending
- 44302 #include <signal.h>
- 44303
- 44304 PUBLIC int sigpending(set)
- 44305 sigset_t *set;
- 44306 {
- 44307 message m;
- 44308
- 44309 if (_syscall(MM, SIGPENDING, &m) < 0) return(-1);
- 44310 *set = (sigset_t) m.m2_l1;
- 44311 return(m.m_type);
- 44312 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_sigprocmask.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 44400 #include <lib.h>
- 44401 #define sigprocmask _sigprocmask
- 44402 #include <signal.h>
- 44403
- 44404 PUBLIC int sigprocmask(how, set, oset)
- 44405 int how;
- 44406 _CONST sigset_t *set;
- 44407 sigset_t *oset;
- 44408 {
- 44409 message m;
- 44410
- 44411 if (set == (sigset_t *) NULL) {
- 44412 m.m2_i1 = SIG_INQUIRE;
- 44413 m.m2_l1 = 0;
- 44414 } else {
- 44415 m.m2_i1 = how;
- 44416 m.m2_l1 = (long) *set;
- 44417 }
- 44418 if (_syscall(MM, SIGPROCMASK, &m) < 0) return(-1);
- 44419 if (oset != (sigset_t *) NULL) *oset = (sigset_t) (m.m2_l1);
- 44420 return(m.m_type);
- 44421 }
- .Ep 414 src/lib/posix/_sigreturn.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_sigreturn.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 44500 #include <lib.h>
- 44501 #define sigfillset _sigfillset
- 44502 #define sigjmp _sigjmp
- 44503 #define sigprocmask _sigprocmask
- 44504 #define sigreturn _sigreturn
- 44505 #include <sys/sigcontext.h>
- 44506 #include <setjmp.h>
- 44507 #include <signal.h>
- 44508
- 44509 _PROTOTYPE( int sigjmp, (jmp_buf jb, int retval));
- 44510
- 44511 #if (_SETJMP_SAVES_REGS == 0)
- 44512 /* 'sigreturn' using a short format jmp_buf (no registers saved). */
- 44513 PUBLIC int sigjmp(jb, retval)
- 44514 jmp_buf jb;
- 44515 int retval;
- 44516 {
- 44517 struct sigcontext sc;
- 44518
- 44519 sc.sc_flags = jb[0].__flags;
- 44520 sc.sc_mask = jb[0].__mask;
- 44521
- 44522 #if (CHIP == INTEL)
- 44523 sc.sc_pc = (int) jb[0].__pc;
- 44524 sc.sc_sp = (int) jb[0].__sp;
- 44525 sc.sc_fp = (int) jb[0].__lb;
- 44526 #endif
- 44527
- 44528 #if (CHIP == M68000)
- 44529 sc.sc_pc = (long) jb[0].__pc;
- 44530 sc.sc_sp = (long) jb[0].__sp;
- 44531 sc.sc_fp = (long) jb[0].__lb;
- 44532 #endif
- 44533
- 44534 sc.sc_retreg = retval;
- 44535 return sigreturn(&sc);
- 44536 }
- 44537 #endif
- 44538
- 44539 PUBLIC int sigreturn(scp)
- 44540 register struct sigcontext *scp;
- 44541 {
- 44542 sigset_t set;
- 44543
- 44544 /* The message can't be on the stack, because the stack will vanish out
- 44545 * from under us. The send part of sendrec will succeed, but when
- 44546 * a message is sent to restart the current process, who knows what will
- 44547 * be in the place formerly occupied by the message?
- 44548 */
- 44549 static message m;
- 44550
- 44551 /* Protect against race conditions by blocking all interrupts. */
- 44552 sigfillset(&set); /* splhi */
- 44553 sigprocmask(SIG_SETMASK, &set, (sigset_t *) NULL);
- 44554
- .Op 415 src/lib/posix/_sigreturn.c
- 44555 m.m2_l1 = scp->sc_mask;
- 44556 m.m2_i2 = scp->sc_flags;
- 44557 m.m2_p1 = (char *) scp;
- 44558 return(_syscall(MM, SIGRETURN, &m)); /* normally this doesn't return */
- 44559 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_sigset.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 44600 #include <lib.h>
- 44601 /* XXX - these have to be hidden because signal() uses them and signal() is
- 44602 * ANSI and not POSIX. It would be surely be better to use macros for the
- 44603 * library and system uses, and perhaps macros as well as functions for the
- 44604 * POSIX user interface. The macros would not need underlines. It may be
- 44605 * inconvenient to match the exact semantics of the current functions
- 44606 * because the interface is bloated by reporting errors. For library and
- 44607 * system uses, the signal number is mostly already known to be valid
- 44608 * before the sigset-changing routines are called.
- 44609 */
- 44610 #define sigaddset _sigaddset
- 44611 #define sigdelset _sigdelset
- 44612 #define sigemptyset _sigemptyset
- 44613 #define sigfillset _sigfillset
- 44614 #define sigismember _sigismember
- 44615 #include <signal.h>
- 44616
- 44617 /* Low bit of signal masks. */
- 44618 #define SIGBIT_0 ((sigset_t) 1)
- 44619
- 44620 /* Mask of valid signals (0 - _NSIG). Assume the shift doesn't overflow. */
- 44621 #define SIGMASK ((SIGBIT_0 << (_NSIG + 1)) - 1)
- 44622
- 44623 #define sigisvalid(signo) ((unsigned) (signo) <= _NSIG)
- 44624
- 44625 PUBLIC int sigaddset(set, signo)
- 44626 sigset_t *set;
- 44627 int signo;
- 44628 {
- 44629 if (!sigisvalid(signo)) {
- 44630 errno = EINVAL;
- 44631 return -1;
- 44632 }
- 44633 *set |= SIGBIT_0 << signo;
- 44634 return 0;
- 44635 }
-
- 44637 PUBLIC int sigdelset(set, signo)
- 44638 sigset_t *set;
- 44639 int signo;
- 44640 {
- 44641 if (!sigisvalid(signo)) {
- 44642 errno = EINVAL;
- 44643 return -1;
- 44644 }
- .Ep 416 src/lib/posix/_sigset.c
- 44645 *set &= ~(SIGBIT_0 << signo);
- 44646 return 0;
- 44647 }
-
- 44649 PUBLIC int sigemptyset(set)
- 44650 sigset_t *set;
- 44651 {
- 44652 *set = 0;
- 44653 return 0;
- 44654 }
-
- 44656 PUBLIC int sigfillset(set)
- 44657 sigset_t *set;
- 44658 {
- 44659 *set = SIGMASK;
- 44660 return 0;
- 44661 }
-
- 44663 PUBLIC int sigismember(set, signo)
- 44664 sigset_t *set;
- 44665 int signo;
- 44666 {
- 44667 if (!sigisvalid(signo)) {
- 44668 errno = EINVAL;
- 44669 return -1;
- 44670 }
- 44671 if (*set & (SIGBIT_0 << signo))
- 44672 return 1;
- 44673 return 0;
- 44674 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_sigsetjmp.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 44700 #include <lib.h>
- 44701 #include <sys/sigcontext.h>
- 44702 #include <setjmp.h>
- 44703
- 44704 PUBLIC void siglongjmp(env, val)
- 44705 sigjmp_buf env;
- 44706 int val;
- 44707 {
- 44708 if (env[0].__flags & SC_SIGCONTEXT)
- 44709 longjmp(env, val);
- 44710 else
- 44711 _longjmp(env, val);
- 44712 }
- .Op 417 src/lib/posix/_sigsuspend.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_sigsuspend.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 44800 #include <lib.h>
- 44801 #define sigsuspend _sigsuspend
- 44802 #include <signal.h>
- 44803
- 44804 PUBLIC int sigsuspend(set)
- 44805 _CONST sigset_t *set;
- 44806 {
- 44807 message m;
- 44808
- 44809 m.m2_l1 = (long) *set;
- 44810 return(_syscall(MM, SIGSUSPEND, &m));
- 44811 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_sleep.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 44900 /* sleep(3)
- 44901 *
- 44902 * Sleep(n) pauses for 'n' seconds by scheduling an alarm interrupt.
- 44903 *
- 44904 * Changed to conform with POSIX Terrence W. Holm Oct. 1988
- 44905 */
- 44906
- 44907 #include <lib.h>
- 44908 #define sleep _sleep
- 44909 #include <signal.h>
- 44910 #include <unistd.h>
- 44911
- 44912 FORWARD _PROTOTYPE( void _alfun, (int signo) );
- 44913
- 44914 PRIVATE void _alfun(signo)
- 44915 int signo;
- 44916 {
- 44917 /* Dummy signal handler used with sleep() below. */
- 44918 }
-
- 44920 PUBLIC unsigned sleep(secs)
- 44921 unsigned secs;
- 44922 {
- 44923 unsigned current_secs;
- 44924 unsigned remaining_secs;
- 44925 struct sigaction act, oact;
- 44926 sigset_t ss;
- 44927
- 44928 if (secs == 0) return(0);
- 44929
- 44930 current_secs = alarm(0); /* is there currently an alarm? */
- 44931
- 44932 if (current_secs == 0 || current_secs > secs) {
- 44933 act.sa_flags = 0;
- 44934 act.sa_mask = 0;
- .Ep 418 src/lib/posix/_sleep.c
- 44935 act.sa_handler = _alfun;
- 44936 sigaction(SIGALRM, &act, &oact);
- 44937
- 44938 alarm(secs);
- 44939 sigemptyset(&ss);
- 44940 sigsuspend(&ss);
- 44941 remaining_secs = alarm(0);
- 44942
- 44943 sigaction(SIGALRM, &oact, (struct sigaction *) NULL);
- 44944
- 44945 if (current_secs > secs)
- 44946 alarm(current_secs - (secs - remaining_secs));
- 44947
- 44948 return(remaining_secs);
- 44949 }
- 44950
- 44951 /* Current_secs <= secs, ie. alarm should occur before secs. */
- 44952
- 44953 alarm(current_secs);
- 44954 pause();
- 44955 remaining_secs = alarm(0);
- 44956
- 44957 alarm(remaining_secs);
- 44958
- 44959 return(secs - (current_secs - remaining_secs));
- 44960 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_stat.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 45000 #include <lib.h>
- 45001 #define stat _stat
- 45002 #include <sys/stat.h>
- 45003 #include <string.h>
- 45004
- 45005 PUBLIC int stat(name, buffer)
- 45006 _CONST char *name;
- 45007 struct stat *buffer;
- 45008 {
- 45009 message m;
- 45010
- 45011 m.m1_i1 = strlen(name) + 1;
- 45012 m.m1_p1 = (char *) name;
- 45013 m.m1_p2 = (char *) buffer;
- 45014 return(_syscall(FS, STAT, &m));
- 45015 }
- .Op 419 src/lib/posix/_stime.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_stime.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 45100 #include <lib.h>
- 45101 #define stime _stime
- 45102 #include <minix/minlib.h>
- 45103 #include <time.h>
- 45104
- 45105 PUBLIC int stime(top)
- 45106 long *top;
- 45107 {
- 45108 message m;
- 45109
- 45110 m.m2_l1 = *top;
- 45111 return(_syscall(FS, STIME, &m));
- 45112 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_sync.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 45200 #include <lib.h>
- 45201 #define sync _sync
- 45202 #include <unistd.h>
- 45203
- 45204 PUBLIC int sync()
- 45205 {
- 45206 message m;
- 45207
- 45208 return(_syscall(FS, SYNC, &m));
- 45209 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_tcdrain.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 45300 /*
- 45301 posix/_tcdrain.c
- 45302
- 45303 Created: July 26, 1994 by Philip Homburg
- 45304 */
- 45305
- 45306 #define tcdrain _tcdrain
- 45307 #define ioctl _ioctl
- 45308 #include <termios.h>
- 45309 #include <sys/ioctl.h>
- 45310
- 45311 int tcdrain(fd)
- 45312 int fd;
- 45313 {
- 45314 return(ioctl(fd, TCDRAIN, (void *)0));
- .Ep 420 src/lib/posix/_tcdrain.c
- 45315 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_tcflow.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 45400 /*
- 45401 posix/_tcflow.c
- 45402
- 45403 Created: June 8, 1993 by Philip Homburg
- 45404 */
- 45405
- 45406 #define tcflow _tcflow
- 45407 #define ioctl _ioctl
- 45408 #include <termios.h>
- 45409 #include <sys/ioctl.h>
- 45410
- 45411 int tcflow(fd, action)
- 45412 int fd;
- 45413 int action;
- 45414 {
- 45415 return(ioctl(fd, TCFLOW, &action));
- 45416 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_tcflush.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 45500 /* tcflush() - flush buffered characters Author: Kees J. Bot
- 45501 * 13 Jan 1994
- 45502 */
- 45503 #define tcflush _tcflush
- 45504 #define ioctl _ioctl
- 45505 #include <termios.h>
- 45506 #include <sys/ioctl.h>
- 45507
- 45508 int tcflush(int fd, int queue_selector)
- 45509 {
- 45510 return(ioctl(fd, TCFLSH, &queue_selector));
- 45511 }
- .Op 421 src/lib/posix/_tcgetattr.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_tcgetattr.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 45600 #define tcgetattr _tcgetattr
- 45601 #define ioctl _ioctl
- 45602 #include <sys/ioctl.h>
- 45603 #include <errno.h>
- 45604 #include <termios.h>
- 45605
- 45606 int tcgetattr(fd, termios_p)
- 45607 int fd;
- 45608 struct termios *termios_p;
- 45609 {
- 45610 return(ioctl(fd, TCGETS, termios_p));
- 45611 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_tcsendbreak.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 45700 /* tcsendbreak() - send a break Author: Kees J. Bot
- 45701 * 13 Jan 1994
- 45702 */
- 45703 #define tcsendbreak _tcsendbreak
- 45704 #define ioctl _ioctl
- 45705 #include <termios.h>
- 45706 #include <sys/ioctl.h>
- 45707
- 45708 int tcsendbreak(int fd, int duration)
- 45709 {
- 45710 return(ioctl(fd, TCSBRK, &duration));
- 45711 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_tcsetattr.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 45800 /*
- 45801 posix/_tcsetattr.c
- 45802
- 45803 Created: June 11, 1993 by Philip Homburg
- 45804 */
- 45805
- 45806 #define tcsetattr _tcsetattr
- 45807 #define ioctl _ioctl
- 45808 #include <errno.h>
- 45809 #include <termios.h>
- 45810 #include <sys/ioctl.h>
- 45811 #include <sys/types.h>
- 45812
- 45813 int tcsetattr(fd, opt_actions, termios_p)
- 45814 int fd;
- .Ep 422 src/lib/posix/_tcsetattr.c
- 45815 int opt_actions;
- 45816 _CONST struct termios *termios_p;
- 45817 {
- 45818 int request;
- 45819
- 45820 switch(opt_actions)
- 45821 {
- 45822 case TCSANOW: request = TCSETS; break;
- 45823 case TCSADRAIN: request = TCSETSW; break;
- 45824 case TCSAFLUSH: request = TCSETSF; break;
- 45825 default: errno = EINVAL; return(-1);
- 45826 };
- 45827 return(ioctl(fd, request, (void *) termios_p));
- 45828 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_time.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 45900 #include <lib.h>
- 45901 #define time _time
- 45902 #include <time.h>
- 45903
- 45904 PUBLIC time_t time(tp)
- 45905 time_t *tp;
- 45906 {
- 45907 message m;
- 45908
- 45909 if (_syscall(FS, TIME, &m) < 0) return( (time_t) -1);
- 45910 if (tp != (time_t *) 0) *tp = m.m2_l1;
- 45911 return(m.m2_l1);
- 45912 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_times.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 46000 #include <lib.h>
- 46001 #define times _times
- 46002 #include <sys/times.h>
- 46003 #include <time.h>
- 46004
- 46005 PUBLIC clock_t times(buf)
- 46006 struct tms *buf;
- 46007 {
- 46008 message m;
- 46009
- 46010 m.m4_l5 = 0; /* return this if system is pre-1.6 */
- 46011 if (_syscall(FS, TIMES, &m) < 0) return( (clock_t) -1);
- 46012 buf->tms_utime = m.m4_l1;
- 46013 buf->tms_stime = m.m4_l2;
- 46014 buf->tms_cutime = m.m4_l3;
- 46015 buf->tms_cstime = m.m4_l4;
- 46016 return(m.m4_l5);
- 46017 }
- .Op 423 src/lib/posix/_umask.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_umask.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 46100 #include <lib.h>
- 46101 #define umask _umask
- 46102 #include <sys/stat.h>
- 46103
- 46104 PUBLIC mode_t umask(complmode)
- 46105 Mode_t complmode;
- 46106 {
- 46107 message m;
- 46108
- 46109 m.m1_i1 = complmode;
- 46110 return( (mode_t) _syscall(FS, UMASK, &m));
- 46111 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_umount.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 46200 #include <lib.h>
- 46201 #define umount _umount
- 46202 #include <unistd.h>
- 46203
- 46204 PUBLIC int umount(name)
- 46205 _CONST char *name;
- 46206 {
- 46207 message m;
- 46208
- 46209 _loadname(name, &m);
- 46210 return(_syscall(FS, UMOUNT, &m));
- 46211 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_uname.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 46300 /* uname() - get system info Author: Kees J. Bot
- 46301 * 7 Nov 1994
- 46302 * Returns information about the Minix system. Alas most
- 46303 * of it is gathered at compile time, so machine is wrong, and
- 46304 * release and version become wrong if not recompiled.
- 46305 * More chip types and Minix versions need to be added.
- 46306 */
- 46307 #define uname _uname
- 46308 #define open _open
- 46309 #define read _read
- 46310 #define close _close
- 46311 #include <sys/types.h>
- 46312 #include <sys/utsname.h>
- 46313 #include <unistd.h>
- 46314 #include <fcntl.h>
- .Ep 424 src/lib/posix/_uname.c
- 46315 #include <string.h>
- 46316 #include <errno.h>
- 46317 #include <minix/config.h>
- 46318 #include <minix/minlib.h>
- 46319
- 46320 int uname(name) struct utsname *name;
- 46321 {
- 46322 int hf, n, err;
- 46323 char *nl;
- 46324
- 46325 /* Read the node name from /etc/hostname.file. */
- 46326 if ((hf = open("/etc/hostname.file", O_RDONLY)) < 0) {
- 46327 if (errno != ENOENT) return(-1);
- 46328 strcpy(name->nodename, "noname");
- 46329 } else {
- 46330 n = read(hf, name->nodename, sizeof(name->nodename) - 1);
- 46331 err = errno;
- 46332 close(hf);
- 46333 errno = err;
- 46334 if (n < 0) return(-1);
- 46335 name->nodename[n] = 0;
- 46336 if ((nl = strchr(name->nodename, 'n')) != NULL) {
- 46337 memset(nl, 0, (name->nodename + sizeof(name->nodename)) - nl);
- 46338 }
- 46339 }
- 46340
- 46341 strcpy(name->sysname, "Minix");
- 46342 strcpy(name->release, OS_RELEASE);
- 46343 strcpy(name->version, OS_VERSION);
- 46344 #if (CHIP == INTEL)
- 46345 name->machine[0] = 'i';
- 46346 strcpy(name->machine + 1, itoa(getprocessor()));
- 46347 #if _WORD_SIZE == 4
- 46348 strcpy(name->arch, "i386");
- 46349 #else
- 46350 strcpy(name->arch, "i86");
- 46351 #endif
- 46352 #endif
- 46353 return(0);
- 46354 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_unlink.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 46400 #include <lib.h>
- 46401 #define unlink _unlink
- 46402 #include <unistd.h>
- 46403
- 46404 PUBLIC int unlink(name)
- 46405 _CONST char *name;
- 46406 {
- 46407 message m;
- 46408
- 46409 _loadname(name, &m);
- .Op 425 src/lib/posix/_unlink.c
- 46410 return(_syscall(FS, UNLINK, &m));
- 46411 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_utime.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 46500 /* utime(2) for POSIX Authors: Terrence W. Holm & Edwin L. Froese */
- 46501
- 46502 #include <lib.h>
- 46503 #define utime _utime
- 46504 #include <string.h>
- 46505 #include <utime.h>
- 46506
- 46507 PUBLIC int utime(name, timp)
- 46508 _CONST char *name;
- 46509 _CONST struct utimbuf *timp;
- 46510 {
- 46511 message m;
- 46512
- 46513 if (timp == NULL) {
- 46514 m.m2_i1 = 0; /* name size 0 means NULL `timp' */
- 46515 m.m2_i2 = strlen(name) + 1; /* actual size here */
- 46516 } else {
- 46517 m.m2_l1 = timp->actime;
- 46518 m.m2_l2 = timp->modtime;
- 46519 m.m2_i1 = strlen(name) + 1;
- 46520 }
- 46521 m.m2_p1 = (char *) name;
- 46522 return(_syscall(FS, UTIME, &m));
- 46523 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_wait.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 46600 #include <lib.h>
- 46601 #define wait _wait
- 46602 #include <sys/wait.h>
- 46603
- 46604 PUBLIC pid_t wait(status)
- 46605 int *status;
- 46606 {
- 46607 message m;
- 46608
- 46609 if (_syscall(MM, WAIT, &m) < 0) return(-1);
- 46610 if (status != 0) *status = m.m2_i1;
- 46611 return(m.m_type);
- 46612 }
- .Ep 426 src/lib/posix/_waitpid.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_waitpid.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 46700 #include <lib.h>
- 46701 #define waitpid _waitpid
- 46702 #include <sys/wait.h>
- 46703
- 46704 PUBLIC pid_t waitpid(pid, status, options)
- 46705 pid_t pid;
- 46706 int *status;
- 46707 int options;
- 46708 {
- 46709 message m;
- 46710
- 46711 m.m1_i1 = pid;
- 46712 m.m1_i2 = options;
- 46713 if (_syscall(MM, WAITPID, &m) < 0) return(-1);
- 46714 if (status != 0) *status = m.m2_i1;
- 46715 return m.m_type;
- 46716 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/posix/_write.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 46800 #include <lib.h>
- 46801 #define write _write
- 46802 #include <unistd.h>
- 46803
- 46804 PUBLIC ssize_t write(fd, buffer, nbytes)
- 46805 int fd;
- 46806 _CONST void *buffer;
- 46807 size_t nbytes;
- 46808 {
- 46809 message m;
- 46810
- 46811 m.m1_i1 = fd;
- 46812 m.m1_i2 = nbytes;
- 46813 m.m1_p1 = (char *) buffer;
- 46814 return(_syscall(FS, WRITE, &m));
- 46815 }
- .Op 427 src/lib/stdio/loc_incl.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/stdio/loc_incl.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 46900 /*
- 46901 * loc_incl.h - local include file for stdio library
- 46902 */
- 46903 /* $Header: loc_incl.h,v 1.5 91/06/10 17:07:18 ceriel Exp $ */
- 46904
- 46905 #include <stdio.h>
- 46906
- 46907 #define io_testflag(p,x) ((p)->_flags & (x))
- 46908
- 46909 #include <stdarg.h>
- 46910
- 46911 #ifdef _ANSI
- 46912 int _doprnt(const char *format, va_list ap, FILE *stream);
- 46913 int _doscan(FILE * stream, const char *format, va_list ap);
- 46914 char *_i_compute(unsigned long val, int base, char *s, int nrdigits);
- 46915 char *_f_print(va_list *ap, int flags, char *s, char c, int precision);
- 46916 void __cleanup(void);
- 46917
- 46918 FILE *popen(const char *command, const char *type);
- 46919 FILE *fdopen(int fd, const char *mode);
- 46920
- 46921 #ifndef NOFLOAT
- 46922 char *_ecvt(long double value, int ndigit, int *decpt, int *sign);
- 46923 char *_fcvt(long double value, int ndigit, int *decpt, int *sign);
- 46924 #endif /* NOFLOAT */
- 46925 #endif
- 46926
- 46927 #define FL_LJUST 0x0001 /* left-justify field */
- 46928 #define FL_SIGN 0x0002 /* sign in signed conversions */
- 46929 #define FL_SPACE 0x0004 /* space in signed conversions */
- 46930 #define FL_ALT 0x0008 /* alternate form */
- 46931 #define FL_ZEROFILL 0x0010 /* fill with zero's */
- 46932 #define FL_SHORT 0x0020 /* optional h */
- 46933 #define FL_LONG 0x0040 /* optional l */
- 46934 #define FL_LONGDOUBLE 0x0080 /* optional L */
- 46935 #define FL_WIDTHSPEC 0x0100 /* field width is specified */
- 46936 #define FL_PRECSPEC 0x0200 /* precision is specified */
- 46937 #define FL_SIGNEDCONV 0x0400 /* may contain a sign */
- 46938 #define FL_NOASSIGN 0x0800 /* do not assign (in scanf) */
- 46939 #define FL_NOMORE 0x1000 /* all flags collected */
- .Ep 428 src/lib/stdio/clearerr.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/stdio/clearerr.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 47000 /*
- 47001 * clearerr.c - clear error and end-of-file indicators of a stream
- 47002 */
- 47003 /* $Header: clearerr.c,v 1.2 91/01/03 14:23:54 ceriel Exp $ */
- 47004
- 47005 #include <stdio.h>
- 47006
- 47007 void
- 47008 (clearerr)(FILE *stream)
- 47009 {
- 47010 clearerr(stream);
- 47011 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/stdio/data.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 47100 /*
- 47101 * data.c - this is the initialization for the standard streams
- 47102 */
- 47103 /* $Header: data.c,v 1.3 90/04/09 15:35:09 eck Exp $ */
- 47104
- 47105 #include <stdio.h>
- 47106
- 47107 struct __iobuf __stdin = {
- 47108 0, 0, _IOREAD, 0,
- 47109 (unsigned char *)NULL, (unsigned char *)NULL,
- 47110 };
- 47111
- 47112 struct __iobuf __stdout = {
- 47113 0, 1, _IOWRITE, 0,
- 47114 (unsigned char *)NULL, (unsigned char *)NULL,
- 47115 };
- 47116
- 47117 struct __iobuf __stderr = {
- 47118 0, 2, _IOWRITE | _IOLBF, 0,
- 47119 (unsigned char *)NULL, (unsigned char *)NULL,
- 47120 };
- 47121
- 47122 FILE *__iotab[FOPEN_MAX] = {
- 47123 &__stdin,
- 47124 &__stdout,
- 47125 &__stderr,
- 47126 0
- 47127 };
- .Op 429 src/lib/stdio/doprnt.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/stdio/doprnt.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 47200 /*
- 47201 * doprnt.c - print formatted output
- 47202 */
- 47203 /* $Header: doprnt.c,v 1.8 91/06/10 17:06:53 ceriel Exp $ */
- 47204
- 47205 #include <ctype.h>
- 47206 #include <stdio.h>
- 47207 #include <stdarg.h>
- 47208 #include <string.h>
- 47209 #include "loc_incl.h"
- 47210
- 47211 /* gnum() is used to get the width and precision fields of a format. */
- 47212 static const char *
- 47213 gnum(register const char *f, int *ip, va_list *app)
- 47214 {
- 47215 register int i, c;
- 47216
- 47217 if (*f == '*') {
- 47218 *ip = va_arg((*app), int);
- 47219 f++;
- 47220 } else {
- 47221 i = 0;
- 47222 while ((c = *f - '0') >= 0 && c <= 9) {
- 47223 i = i*10 + c;
- 47224 f++;
- 47225 }
- 47226 *ip = i;
- 47227 }
- 47228 return f;
- 47229 }
-
- 47231 #if _EM_WSIZE == _EM_PSIZE
- 47232 #define set_pointer(flags) /* nothing */
- 47233 #elif _EM_LSIZE == _EM_PSIZE
- 47234 #define set_pointer(flags) (flags |= FL_LONG)
- 47235 #else
- 47236 #error garbage pointer size
- 47237 #define set_pointer(flags) /* compilation might continue */
- 47238 #endif
- 47239
- 47240 /* print an ordinal number */
- 47241 static char *
- 47242 o_print(va_list *ap, int flags, char *s, char c, int precision, int is_signed)
- 47243 {
- 47244 long signed_val;
- 47245 unsigned long unsigned_val;
- 47246 char *old_s = s;
- 47247 int base;
- 47248
- 47249 switch (flags & (FL_SHORT | FL_LONG)) {
- 47250 case FL_SHORT:
- 47251 if (is_signed) {
- 47252 signed_val = (short) va_arg(*ap, int);
- 47253 } else {
- 47254 unsigned_val = (unsigned short) va_arg(*ap, unsigned);
- .Ep 430 src/lib/stdio/doprnt.c
- 47255 }
- 47256 break;
- 47257 case FL_LONG:
- 47258 if (is_signed) {
- 47259 signed_val = va_arg(*ap, long);
- 47260 } else {
- 47261 unsigned_val = va_arg(*ap, unsigned long);
- 47262 }
- 47263 break;
- 47264 default:
- 47265 if (is_signed) {
- 47266 signed_val = va_arg(*ap, int);
- 47267 } else {
- 47268 unsigned_val = va_arg(*ap, unsigned int);
- 47269 }
- 47270 break;
- 47271 }
- 47272
- 47273 if (is_signed) {
- 47274 if (signed_val < 0) {
- 47275 *s++ = '-';
- 47276 signed_val = -signed_val;
- 47277 } else if (flags & FL_SIGN) *s++ = '+';
- 47278 else if (flags & FL_SPACE) *s++ = ' ';
- 47279 unsigned_val = signed_val;
- 47280 }
- 47281 if ((flags & FL_ALT) && (c == 'o')) *s++ = '0';
- 47282 if (!unsigned_val) {
- 47283 if (!precision)
- 47284 return s;
- 47285 } else if (((flags & FL_ALT) && (c == 'x' || c == 'X'))
- 47286 || c == 'p') {
- 47287 *s++ = '0';
- 47288 *s++ = (c == 'X' ? 'X' : 'x');
- 47289 }
- 47290
- 47291 switch (c) {
- 47292 case 'b': base = 2; break;
- 47293 case 'o': base = 8; break;
- 47294 case 'd':
- 47295 case 'i':
- 47296 case 'u': base = 10; break;
- 47297 case 'x':
- 47298 case 'X':
- 47299 case 'p': base = 16; break;
- 47300 }
- 47301
- 47302 s = _i_compute(unsigned_val, base, s, precision);
- 47303
- 47304 if (c == 'X')
- 47305 while (old_s != s) {
- 47306 *old_s = toupper(*old_s);
- 47307 old_s++;
- 47308 }
- 47309
- 47310 return s;
- 47311 }
-
- 47313 int
- 47314 _doprnt(register const char *fmt, va_list ap, FILE *stream)
- .Op 431 src/lib/stdio/doprnt.c
- 47315 {
- 47316 register char *s;
- 47317 register int j;
- 47318 int i, c, width, precision, zfill, flags, between_fill;
- 47319 int nrchars=0;
- 47320 const char *oldfmt;
- 47321 char *s1, buf[1025];
- 47322
- 47323 while (c = *fmt++) {
- 47324 if (c != '%') {
- 47325 #ifdef CPM
- 47326 if (c == 'n') {
- 47327 if (putc('r', stream) == EOF)
- 47328 return nrchars ? -nrchars : -1;
- 47329 nrchars++;
- 47330 }
- 47331 #endif
- 47332 if (putc(c, stream) == EOF)
- 47333 return nrchars ? -nrchars : -1;
- 47334 nrchars++;
- 47335 continue;
- 47336 }
- 47337 flags = 0;
- 47338 do {
- 47339 switch(*fmt) {
- 47340 case '-': flags |= FL_LJUST; break;
- 47341 case '+': flags |= FL_SIGN; break;
- 47342 case ' ': flags |= FL_SPACE; break;
- 47343 case '#': flags |= FL_ALT; break;
- 47344 case '0': flags |= FL_ZEROFILL; break;
- 47345 default: flags |= FL_NOMORE; continue;
- 47346 }
- 47347 fmt++;
- 47348 } while(!(flags & FL_NOMORE));
- 47349
- 47350 oldfmt = fmt;
- 47351 fmt = gnum(fmt, &width, &ap);
- 47352 if (fmt != oldfmt) flags |= FL_WIDTHSPEC;
- 47353
- 47354 if (*fmt == '.') {
- 47355 fmt++; oldfmt = fmt;
- 47356 fmt = gnum(fmt, &precision, &ap);
- 47357 if (precision >= 0) flags |= FL_PRECSPEC;
- 47358 }
- 47359
- 47360 if ((flags & FL_WIDTHSPEC) && width < 0) {
- 47361 width = -width;
- 47362 flags |= FL_LJUST;
- 47363 }
- 47364 if (!(flags & FL_WIDTHSPEC)) width = 0;
- 47365
- 47366 if (flags & FL_SIGN) flags &= ~FL_SPACE;
- 47367
- 47368 if (flags & FL_LJUST) flags &= ~FL_ZEROFILL;
- 47369
- 47370
- 47371 s = s1 = buf;
- 47372
- 47373 switch (*fmt) {
- 47374 case 'h': flags |= FL_SHORT; fmt++; break;
- .Ep 432 src/lib/stdio/doprnt.c
- 47375 case 'l': flags |= FL_LONG; fmt++; break;
- 47376 case 'L': flags |= FL_LONGDOUBLE; fmt++; break;
- 47377 }
- 47378
- 47379 switch (c = *fmt++) {
- 47380 default:
- 47381 #ifdef CPM
- 47382 if (c == 'n') {
- 47383 if (putc('r', stream) == EOF)
- 47384 return nrchars ? -nrchars : -1;
- 47385 nrchars++;
- 47386 }
- 47387 #endif
- 47388 if (putc(c, stream) == EOF)
- 47389 return nrchars ? -nrchars : -1;
- 47390 nrchars++;
- 47391 continue;
- 47392 case 'n':
- 47393 if (flags & FL_SHORT)
- 47394 *va_arg(ap, short *) = (short) nrchars;
- 47395 else if (flags & FL_LONG)
- 47396 *va_arg(ap, long *) = (long) nrchars;
- 47397 else
- 47398 *va_arg(ap, int *) = (int) nrchars;
- 47399 continue;
- 47400 case 's':
- 47401 s1 = va_arg(ap, char *);
- 47402 if (s1 == NULL)
- 47403 s1 = "(null)";
- 47404 s = s1;
- 47405 while (precision || !(flags & FL_PRECSPEC)) {
- 47406 if (*s == ' ')
- 47407 break;
- 47408 s++;
- 47409 precision--;
- 47410 }
- 47411 break;
- 47412 case 'p':
- 47413 set_pointer(flags);
- 47414 /* fallthrough */
- 47415 case 'b':
- 47416 case 'o':
- 47417 case 'u':
- 47418 case 'x':
- 47419 case 'X':
- 47420 if (!(flags & FL_PRECSPEC)) precision = 1;
- 47421 else if (c != 'p') flags &= ~FL_ZEROFILL;
- 47422 s = o_print(&ap, flags, s, c, precision, 0);
- 47423 break;
- 47424 case 'd':
- 47425 case 'i':
- 47426 flags |= FL_SIGNEDCONV;
- 47427 if (!(flags & FL_PRECSPEC)) precision = 1;
- 47428 else flags &= ~FL_ZEROFILL;
- 47429 s = o_print(&ap, flags, s, c, precision, 1);
- 47430 break;
- 47431 case 'c':
- 47432 *s++ = va_arg(ap, int);
- 47433 break;
- 47434 #ifndef NOFLOAT
- .Op 433 src/lib/stdio/doprnt.c
- 47435 case 'G':
- 47436 case 'g':
- 47437 if ((flags & FL_PRECSPEC) && (precision == 0))
- 47438 precision = 1;
- 47439 case 'f':
- 47440 case 'E':
- 47441 case 'e':
- 47442 if (!(flags & FL_PRECSPEC))
- 47443 precision = 6;
- 47444
- 47445 if (precision >= sizeof(buf))
- 47446 precision = sizeof(buf) - 1;
- 47447
- 47448 flags |= FL_SIGNEDCONV;
- 47449 s = _f_print(&ap, flags, s, c, precision);
- 47450 break;
- 47451 #endif /* NOFLOAT */
- 47452 case 'r':
- 47453 ap = va_arg(ap, va_list);
- 47454 fmt = va_arg(ap, char *);
- 47455 continue;
- 47456 }
- 47457 zfill = ' ';
- 47458 if (flags & FL_ZEROFILL) zfill = '0';
- 47459 j = s - s1;
- 47460
- 47461 /* between_fill is true under the following conditions:
- 47462 * 1- the fill character is '0'
- 47463 * and
- 47464 * 2a- the number is of the form 0x... or 0X...
- 47465 * or
- 47466 * 2b- the number contains a sign or space
- 47467 */
- 47468 between_fill = 0;
- 47469 if ((flags & FL_ZEROFILL)
- 47470 && (((c == 'x' || c == 'X') && (flags & FL_ALT))
- 47471 || (c == 'p')
- 47472 || ((flags & FL_SIGNEDCONV)
- 47473 && ( *s1 == '+' || *s1 == '-' || *s1 == ' '))))
- 47474 between_fill++;
- 47475
- 47476 if ((i = width - j) > 0)
- 47477 if (!(flags & FL_LJUST)) { /* right justify */
- 47478 nrchars += i;
- 47479 if (between_fill) {
- 47480 if (flags & FL_SIGNEDCONV) {
- 47481 j--; nrchars++;
- 47482 if (putc(*s1++, stream) == EOF)
- 47483 return nrchars ? -nrchars : -1;
- 47484 } else {
- 47485 j -= 2; nrchars += 2;
- 47486 if ((putc(*s1++, stream) == EOF)
- 47487 || (putc(*s1++, stream) == EOF))
- 47488 return nrchars ? -nrchars : -1;
- 47489 }
- 47490 }
- 47491 do {
- 47492 if (putc(zfill, stream) == EOF)
- 47493 return nrchars ? -nrchars : -1;
- 47494 } while (--i);
- .Ep 434 src/lib/stdio/doprnt.c
- 47495 }
- 47496
- 47497 nrchars += j;
- 47498 while (--j >= 0) {
- 47499 if (putc(*s1++, stream) == EOF)
- 47500 return nrchars ? -nrchars : -1;
- 47501 }
- 47502
- 47503 if (i > 0) nrchars += i;
- 47504 while (--i >= 0)
- 47505 if (putc(zfill, stream) == EOF)
- 47506 return nrchars ? -nrchars : -1;
- 47507 }
- 47508 return nrchars;
- 47509 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/stdio/doscan.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 47600 /*
- 47601 * doscan.c - scan formatted input
- 47602 */
- 47603 /* $Header: doscan.c,v 1.9 91/03/26 18:41:47 ceriel Exp $ */
- 47604
- 47605 #include <stdio.h>
- 47606 #include <stdlib.h>
- 47607 #include <ctype.h>
- 47608 #include <stdarg.h>
- 47609 #include "loc_incl.h"
- 47610
- 47611 #if _EM_WSIZE == _EM_PSIZE
- 47612 #define set_pointer(flags) /* nothing */
- 47613 #elif _EM_LSIZE == _EM_PSIZE
- 47614 #define set_pointer(flags) (flags |= FL_LONG)
- 47615 #else
- 47616 #error garbage pointer size
- 47617 #define set_pointer(flags) /* compilation might continue */
- 47618 #endif
- 47619
- 47620 #define NUMLEN 512
- 47621 #define NR_CHARS 256
- 47622
- 47623 static char Xtable[NR_CHARS];
- 47624 static char inp_buf[NUMLEN];
- 47625
- 47626 /* Collect a number of characters which constitite an ordinal number.
- 47627 * When the type is 'i', the base can be 8, 10, or 16, depending on the
- 47628 * first 1 or 2 characters. This means that the base must be adjusted
- 47629 * according to the format of the number. At the end of the function, base
- 47630 * is then set to 0, so strtol() will get the right argument.
- 47631 */
- 47632 static char *
- 47633 o_collect(register int c, register FILE *stream, char type,
- 47634 unsigned int width, int *basep)
- .Op 435 src/lib/stdio/doscan.c
- 47635 {
- 47636 register char *bufp = inp_buf;
- 47637 register int base;
- 47638
- 47639 switch (type) {
- 47640 case 'i': /* i means octal, decimal or hexadecimal */
- 47641 case 'p':
- 47642 case 'x':
- 47643 case 'X': base = 16; break;
- 47644 case 'd':
- 47645 case 'u': base = 10; break;
- 47646 case 'o': base = 8; break;
- 47647 case 'b': base = 2; break;
- 47648 }
- 47649
- 47650 if (c == '-' || c == '+') {
- 47651 *bufp++ = c;
- 47652 if (--width)
- 47653 c = getc(stream);
- 47654 }
- 47655
- 47656 if (width && c == '0' && base == 16) {
- 47657 *bufp++ = c;
- 47658 if (--width)
- 47659 c = getc(stream);
- 47660 if (c != 'x' && c != 'X') {
- 47661 if (type == 'i') base = 8;
- 47662 }
- 47663 else if (width) {
- 47664 *bufp++ = c;
- 47665 if (--width)
- 47666 c = getc(stream);
- 47667 }
- 47668 }
- 47669 else if (type == 'i') base = 10;
- 47670
- 47671 while (width) {
- 47672 if (((base == 10) && isdigit(c))
- 47673 || ((base == 16) && isxdigit(c))
- 47674 || ((base == 8) && isdigit(c) && (c < '8'))
- 47675 || ((base == 2) && isdigit(c) && (c < '2'))) {
- 47676 *bufp++ = c;
- 47677 if (--width)
- 47678 c = getc(stream);
- 47679 }
- 47680 else break;
- 47681 }
- 47682
- 47683 if (width && c != EOF) ungetc(c, stream);
- 47684 if (type == 'i') base = 0;
- 47685 *basep = base;
- 47686 *bufp = ' ';
- 47687 return bufp - 1;
- 47688 }
-
- 47690 #ifndef NOFLOAT
- 47691 /* The function f_collect() reads a string that has the format of a
- 47692 * floating-point number. The function returns as soon as a format-error
- 47693 * is encountered, leaving the offending character in the input. This means
- 47694 * that 1.el leaves the 'l' in the input queue. Since all detection of
- .Ep 436 src/lib/stdio/doscan.c
- 47695 * format errors is done here, _doscan() doesn't call strtod() when it's
- 47696 * not necessary, although the use of the width field can cause incomplete
- 47697 * numbers to be passed to strtod(). (e.g. 1.3e+)
- 47698 */
- 47699 static char *
- 47700 f_collect(register int c, register FILE *stream, register unsigned int width)
- 47701 {
- 47702 register char *bufp = inp_buf;
- 47703 int digit_seen = 0;
- 47704
- 47705 if (c == '-' || c == '+') {
- 47706 *bufp++ = c;
- 47707 if (--width)
- 47708 c = getc(stream);
- 47709 }
- 47710
- 47711 while (width && isdigit(c)) {
- 47712 digit_seen++;
- 47713 *bufp++ = c;
- 47714 if (--width)
- 47715 c = getc(stream);
- 47716 }
- 47717 if (width && c == '.') {
- 47718 *bufp++ = c;
- 47719 if(--width)
- 47720 c = getc(stream);
- 47721 while (width && isdigit(c)) {
- 47722 digit_seen++;
- 47723 *bufp++ = c;
- 47724 if (--width)
- 47725 c = getc(stream);
- 47726 }
- 47727 }
- 47728
- 47729 if (!digit_seen) {
- 47730 if (width && c != EOF) ungetc(c, stream);
- 47731 return inp_buf - 1;
- 47732 }
- 47733 else digit_seen = 0;
- 47734
- 47735 if (width && (c == 'e' || c == 'E')) {
- 47736 *bufp++ = c;
- 47737 if (--width)
- 47738 c = getc(stream);
- 47739 if (width && (c == '+' || c == '-')) {
- 47740 *bufp++ = c;
- 47741 if (--width)
- 47742 c = getc(stream);
- 47743 }
- 47744 while (width && isdigit(c)) {
- 47745 digit_seen++;
- 47746 *bufp++ = c;
- 47747 if (--width)
- 47748 c = getc(stream);
- 47749 }
- 47750 if (!digit_seen) {
- 47751 if (width && c != EOF) ungetc(c,stream);
- 47752 return inp_buf - 1;
- 47753 }
- 47754 }
- .Op 437 src/lib/stdio/doscan.c
- 47755
- 47756 if (width && c != EOF) ungetc(c, stream);
- 47757 *bufp = ' ';
- 47758 return bufp - 1;
- 47759 }
- 47760 #endif /* NOFLOAT */
- 47761
- 47762
- 47763 /*
- 47764 * the routine that does the scanning
- 47765 */
- 47766
- 47767 int
- 47768 _doscan(register FILE *stream, const char *format, va_list ap)
- 47769 {
- 47770 int done = 0; /* number of items done */
- 47771 int nrchars = 0; /* number of characters read */
- 47772 int conv = 0; /* # of conversions */
- 47773 int base; /* conversion base */
- 47774 unsigned long val; /* an integer value */
- 47775 register char *str; /* temporary pointer */
- 47776 char *tmp_string; /* ditto */
- 47777 unsigned width = 0; /* width of field */
- 47778 int flags; /* some flags */
- 47779 int reverse; /* reverse the checking in [...] */
- 47780 int kind;
- 47781 register int ic = EOF; /* the input character */
- 47782 #ifndef NOFLOAT
- 47783 long double ld_val;
- 47784 #endif
- 47785
- 47786 if (!*format) return 0;
- 47787
- 47788 while (1) {
- 47789 if (isspace(*format)) {
- 47790 while (isspace(*format))
- 47791 format++; /* skip whitespace */
- 47792 ic = getc(stream);
- 47793 nrchars++;
- 47794 while (isspace (ic)) {
- 47795 ic = getc(stream);
- 47796 nrchars++;
- 47797 }
- 47798 if (ic != EOF) ungetc(ic,stream);
- 47799 nrchars--;
- 47800 }
- 47801 if (!*format) break; /* end of format */
- 47802
- 47803 if (*format != '%') {
- 47804 ic = getc(stream);
- 47805 nrchars++;
- 47806 if (ic != *format++) break; /* error */
- 47807 continue;
- 47808 }
- 47809 format++;
- 47810 if (*format == '%') {
- 47811 ic = getc(stream);
- 47812 nrchars++;
- 47813 if (ic == '%') {
- 47814 format++;
- .Ep 438 src/lib/stdio/doscan.c
- 47815 continue;
- 47816 }
- 47817 else break;
- 47818 }
- 47819 flags = 0;
- 47820 if (*format == '*') {
- 47821 format++;
- 47822 flags |= FL_NOASSIGN;
- 47823 }
- 47824 if (isdigit (*format)) {
- 47825 flags |= FL_WIDTHSPEC;
- 47826 for (width = 0; isdigit (*format);)
- 47827 width = width * 10 + *format++ - '0';
- 47828 }
- 47829
- 47830 switch (*format) {
- 47831 case 'h': flags |= FL_SHORT; format++; break;
- 47832 case 'l': flags |= FL_LONG; format++; break;
- 47833 case 'L': flags |= FL_LONGDOUBLE; format++; break;
- 47834 }
- 47835 kind = *format;
- 47836 if ((kind != 'c') && (kind != '[') && (kind != 'n')) {
- 47837 do {
- 47838 ic = getc(stream);
- 47839 nrchars++;
- 47840 } while (isspace(ic));
- 47841 if (ic == EOF) break; /* outer while */
- 47842 } else if (kind != 'n') { /* %c or %[ */
- 47843 ic = getc(stream);
- 47844 if (ic == EOF) break; /* outer while */
- 47845 nrchars++;
- 47846 }
- 47847 switch (kind) {