get retval(1) working again
This commit is contained in:
parent
c8c3cbc247
commit
d6909207df
2
libio/Makefile
Normal file
2
libio/Makefile
Normal file
@ -0,0 +1,2 @@
|
||||
libio.o: libio.c libio.h
|
||||
$(CC) -c -o libio.o libio.c
|
@ -3,19 +3,11 @@
|
||||
|
||||
/* Backups of standard library systems for the odd scenario where there is no
|
||||
* standard library but there is the write(2) system call. */
|
||||
static int _isdigit(int c);
|
||||
static int _strlen(char *s);
|
||||
|
||||
/* Wrappers around write(2) */
|
||||
static int _write(int fd, char *s, int n);
|
||||
static int _write1(int fd, int c);
|
||||
|
||||
/* Normally in <ctype.h> */
|
||||
static int
|
||||
_isdigit(int c){
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
|
||||
#if defined USE_SYSTEM_STRING_H
|
||||
# include <string.h>
|
||||
# define _strlen strlen
|
||||
#else
|
||||
/* Normally in <string.h> */
|
||||
static int
|
||||
_strlen(char *s){
|
||||
@ -25,6 +17,22 @@ _strlen(char *s){
|
||||
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined USE_SYSTEM_CTYPE_H
|
||||
# include <ctype.h>
|
||||
# define _isdigit isdigit
|
||||
#else
|
||||
/* Normally in <ctype.h> */
|
||||
static int
|
||||
_isdigit(int c){
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Wrappers around write(2) */
|
||||
static int _write(int fd, char *s, int n);
|
||||
static int _write1(int fd, int c);
|
||||
|
||||
/* Wrapper around write(2) - keeps re-running write(2) until the operation
|
||||
* succeeds in full. Usually unnecessary but still good. */
|
||||
@ -52,7 +60,7 @@ _write1(int fd, int c){
|
||||
|
||||
int
|
||||
fdprint(int fd, char *s){
|
||||
return _write(fd, s, strlen(s));
|
||||
return _write(fd, s, _strlen(s));
|
||||
}
|
||||
|
||||
int
|
||||
|
8
retval/Makefile
Normal file
8
retval/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
retval: retval.o ../libio/libio.o
|
||||
$(CC) -o retval ../libio/libio.o retval.o
|
||||
|
||||
retval.o: retval.c ../libio/libio.h
|
||||
$(CC) -c -I../libio -o retval.o retval.c
|
||||
|
||||
../libio/libio.o: ../libio/libio.c ../libio/libio.h
|
||||
$(MAKE) -C ../libio
|
@ -1,4 +1,5 @@
|
||||
#include <ctype.h> /* isdigit(3) */
|
||||
#include <stdio.h> /* fprintf(3), stderr */
|
||||
#include <sysexits.h> /* EX_USAGE */
|
||||
#include <unistd.h> /* write(2) */
|
||||
#include "libio.h" /* fdprint(3), parse_uint(3) */
|
||||
@ -9,9 +10,7 @@ int main(int argc, char *argv[]){
|
||||
unsigned int s;
|
||||
|
||||
if(argc < 2){
|
||||
usage: write(2, "Usage: ", 7);
|
||||
fdprint(2, argv[0] == NULL ? program_name : argv[0]);
|
||||
write(2, " [status]\n", 10);
|
||||
usage: fprintf(stderr, "Usage: %s [status]\n", argv[0] == NULL ? program_name : argv[0]);
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user