1
0

get retval(1) working again

This commit is contained in:
dtb 2023-08-19 09:25:33 -04:00
parent c8c3cbc247
commit d6909207df
4 changed files with 33 additions and 16 deletions

2
libio/Makefile Normal file
View File

@ -0,0 +1,2 @@
libio.o: libio.c libio.h
$(CC) -c -o libio.o libio.c

View File

@ -3,19 +3,11 @@
/* Backups of standard library systems for the odd scenario where there is no /* Backups of standard library systems for the odd scenario where there is no
* standard library but there is the write(2) system call. */ * 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> */ /* Normally in <string.h> */
static int static int
_strlen(char *s){ _strlen(char *s){
@ -25,6 +17,22 @@ _strlen(char *s){
return i; 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 /* Wrapper around write(2) - keeps re-running write(2) until the operation
* succeeds in full. Usually unnecessary but still good. */ * succeeds in full. Usually unnecessary but still good. */
@ -52,7 +60,7 @@ _write1(int fd, int c){
int int
fdprint(int fd, char *s){ fdprint(int fd, char *s){
return _write(fd, s, strlen(s)); return _write(fd, s, _strlen(s));
} }
int int

8
retval/Makefile Normal file
View 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

View File

@ -1,4 +1,5 @@
#include <ctype.h> /* isdigit(3) */ #include <ctype.h> /* isdigit(3) */
#include <stdio.h> /* fprintf(3), stderr */
#include <sysexits.h> /* EX_USAGE */ #include <sysexits.h> /* EX_USAGE */
#include <unistd.h> /* write(2) */ #include <unistd.h> /* write(2) */
#include "libio.h" /* fdprint(3), parse_uint(3) */ #include "libio.h" /* fdprint(3), parse_uint(3) */
@ -9,9 +10,7 @@ int main(int argc, char *argv[]){
unsigned int s; unsigned int s;
if(argc < 2){ if(argc < 2){
usage: write(2, "Usage: ", 7); usage: fprintf(stderr, "Usage: %s [status]\n", argv[0] == NULL ? program_name : argv[0]);
fdprint(2, argv[0] == NULL ? program_name : argv[0]);
write(2, " [status]\n", 10);
return EX_USAGE; return EX_USAGE;
} }