summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/blkmov.c57
-rw-r--r--lib/bound.c7
-rw-r--r--lib/cvtdec.c11
-rw-r--r--lib/cvtdec0.c9
-rw-r--r--lib/cvthex.c9
-rw-r--r--lib/cvtoct.c12
-rw-r--r--lib/cvtuns.c7
-rw-r--r--lib/cvtuns0.c7
-rw-r--r--lib/klibc.c63
-rw-r--r--lib/memclr.c7
-rw-r--r--lib/memcpy.c5
-rw-r--r--lib/memmove.c49
-rw-r--r--lib/memset.c5
-rw-r--r--lib/pad.c7
-rw-r--r--lib/padstr.c19
-rw-r--r--lib/sprint.c49
-rw-r--r--lib/str2int.c13
-rw-r--r--lib/strcat.c9
-rw-r--r--lib/strcmp.c8
-rw-r--r--lib/strcpy.c7
-rw-r--r--lib/strlen.c7
-rw-r--r--lib/ulibc.c52
22 files changed, 273 insertions, 146 deletions
diff --git a/lib/blkmov.c b/lib/blkmov.c
new file mode 100644
index 0000000..6423810
--- /dev/null
+++ b/lib/blkmov.c
@@ -0,0 +1,57 @@
+/**
+** @file blkmov.c
+**
+** @author Numerous CSCI-452 classes
+**
+** @brief C implementations of common library functions
+*/
+
+#ifndef BLKMOV_SRC_INC
+#define BLKMOV_SRC_INC
+
+#include <common.h>
+
+#include <lib.h>
+
+/**
+** blkmov(dst,src,len)
+**
+** Copy a word-aligned block from src to dst. Deals with overlapping
+** buffers.
+**
+** @param dst Destination buffer
+** @param src Source buffer
+** @param len Buffer size (in bytes)
+*/
+void blkmov(void *dst, const void *src, register uint32_t len)
+{
+ // verify that the addresses are aligned and
+ // the length is a multiple of four bytes
+ if ((((uint32_t)dst) & 0x3) != 0 || (((uint32_t)src) & 0x3) != 0 ||
+ (len & 0x3) != 0) {
+ // something isn't aligned, so just use memmove()
+ memmove(dst, src, len);
+ return;
+ }
+
+ // everything is nicely aligned, so off we go
+ register uint32_t *dest = dst;
+ register const uint32_t *source = src;
+
+ // now copying 32-bit values
+ len /= 4;
+
+ if (source < dest && (source + len) > dest) {
+ source += len;
+ dest += len;
+ while (len-- > 0) {
+ *--dest = *--source;
+ }
+ } else {
+ while (len--) {
+ *dest++ = *source++;
+ }
+ }
+}
+
+#endif
diff --git a/lib/bound.c b/lib/bound.c
index f086473..b1b67da 100644
--- a/lib/bound.c
+++ b/lib/bound.c
@@ -24,11 +24,12 @@
**
** @return The constrained value
*/
-uint32_t bound( uint32_t min, uint32_t value, uint32_t max ) {
- if( value < min ){
+uint32_t bound(uint32_t min, uint32_t value, uint32_t max)
+{
+ if (value < min) {
value = min;
}
- if( value > max ){
+ if (value > max) {
value = max;
}
return value;
diff --git a/lib/cvtdec.c b/lib/cvtdec.c
index 216f147..e95e910 100644
--- a/lib/cvtdec.c
+++ b/lib/cvtdec.c
@@ -26,18 +26,19 @@
**
** NOTE: assumes buf is large enough to hold the resulting string
*/
-int cvtdec( char *buf, int32_t value ) {
+int cvtdec(char *buf, int32_t value)
+{
char *bp = buf;
- if( value < 0 ) {
+ if (value < 0) {
*bp++ = '-';
value = -value;
}
- bp = cvtdec0( bp, value );
- *bp = '\0';
+ bp = cvtdec0(bp, value);
+ *bp = '\0';
- return( bp - buf );
+ return (bp - buf);
}
#endif
diff --git a/lib/cvtdec0.c b/lib/cvtdec0.c
index 87792e0..2f89ad2 100644
--- a/lib/cvtdec0.c
+++ b/lib/cvtdec0.c
@@ -26,16 +26,17 @@
**
** NOTE: assumes buf is large enough to hold the resulting string
*/
-char *cvtdec0( char *buf, int value ) {
+char *cvtdec0(char *buf, int value)
+{
int quotient;
quotient = value / 10;
- if( quotient < 0 ) {
+ if (quotient < 0) {
quotient = 214748364;
value = 8;
}
- if( quotient != 0 ) {
- buf = cvtdec0( buf, quotient );
+ if (quotient != 0) {
+ buf = cvtdec0(buf, quotient);
}
*buf++ = value % 10 + '0';
return buf;
diff --git a/lib/cvthex.c b/lib/cvthex.c
index 5f3da19..8faf853 100644
--- a/lib/cvthex.c
+++ b/lib/cvthex.c
@@ -27,13 +27,14 @@
**
** NOTE: assumes buf is large enough to hold the resulting string
*/
-int cvthex( char *buf, uint32_t value ) {
+int cvthex(char *buf, uint32_t value)
+{
const char hexdigits[] = "0123456789ABCDEF";
int chars_stored = 0;
- for( int i = 0; i < 8; i += 1 ) {
+ for (int i = 0; i < 8; i += 1) {
uint32_t val = value & 0xf0000000;
- if( chars_stored || val != 0 || i == 7 ) {
+ if (chars_stored || val != 0 || i == 7) {
++chars_stored;
val = (val >> 28) & 0xf;
*buf++ = hexdigits[val];
@@ -43,7 +44,7 @@ int cvthex( char *buf, uint32_t value ) {
*buf = '\0';
- return( chars_stored );
+ return (chars_stored);
}
#endif
diff --git a/lib/cvtoct.c b/lib/cvtoct.c
index dafd8ff..0e03cad 100644
--- a/lib/cvtoct.c
+++ b/lib/cvtoct.c
@@ -27,23 +27,23 @@
**
** NOTE: assumes buf is large enough to hold the resulting string
*/
-int cvtoct( char *buf, uint32_t value ) {
+int cvtoct(char *buf, uint32_t value)
+{
int i;
int chars_stored = 0;
char *bp = buf;
uint32_t val;
- val = ( value & 0xc0000000 );
+ val = (value & 0xc0000000);
val >>= 30;
- for( i = 0; i < 11; i += 1 ){
-
- if( i == 10 || val != 0 || chars_stored ) {
+ for (i = 0; i < 11; i += 1) {
+ if (i == 10 || val != 0 || chars_stored) {
chars_stored = 1;
val &= 0x7;
*bp++ = val + '0';
}
value <<= 3;
- val = ( value & 0xe0000000 );
+ val = (value & 0xe0000000);
val >>= 29;
}
*bp = '\0';
diff --git a/lib/cvtuns.c b/lib/cvtuns.c
index a0a686a..b535b34 100644
--- a/lib/cvtuns.c
+++ b/lib/cvtuns.c
@@ -25,10 +25,11 @@
**
** NOTE: assumes buf is large enough to hold the resulting string
*/
-int cvtuns( char *buf, uint32_t value ) {
- char *bp = buf;
+int cvtuns(char *buf, uint32_t value)
+{
+ char *bp = buf;
- bp = cvtuns0( bp, value );
+ bp = cvtuns0(bp, value);
*bp = '\0';
return bp - buf;
diff --git a/lib/cvtuns0.c b/lib/cvtuns0.c
index 6a63573..090f00d 100644
--- a/lib/cvtuns0.c
+++ b/lib/cvtuns0.c
@@ -25,12 +25,13 @@
**
** NOTE: assumes buf is large enough to hold the resulting string
*/
-char *cvtuns0( char *buf, uint32_t value ) {
+char *cvtuns0(char *buf, uint32_t value)
+{
uint32_t quotient;
quotient = value / 10;
- if( quotient != 0 ){
- buf = cvtdec0( buf, quotient );
+ if (quotient != 0) {
+ buf = cvtdec0(buf, quotient);
}
*buf++ = value % 10 + '0';
return buf;
diff --git a/lib/klibc.c b/lib/klibc.c
index ded0c78..6a06a96 100644
--- a/lib/klibc.c
+++ b/lib/klibc.c
@@ -23,12 +23,12 @@
**
** @param ch The character to be printed
*/
-void put_char_or_code( int ch ) {
-
- if( ch >= ' ' && ch < 0x7f ) {
- cio_putchar( ch );
+void put_char_or_code(int ch)
+{
+ if (ch >= ' ' && ch < 0x7f) {
+ cio_putchar(ch);
} else {
- cio_printf( "\\x%02x", ch );
+ cio_printf("\\x%02x", ch);
}
}
@@ -40,30 +40,29 @@ void put_char_or_code( int ch ) {
** @param ebp Initial EBP to use
** @param args Number of function argument values to print
*/
-void backtrace( uint32_t *ebp, uint_t args ) {
-
- cio_puts( "Trace: " );
- if( ebp == NULL ) {
- cio_puts( "NULL ebp, no trace possible\n" );
+void backtrace(uint32_t *ebp, uint_t args)
+{
+ cio_puts("Trace: ");
+ if (ebp == NULL) {
+ cio_puts("NULL ebp, no trace possible\n");
return;
} else {
- cio_putchar( '\n' );
+ cio_putchar('\n');
}
- while( ebp != NULL ){
-
+ while (ebp != NULL) {
// get return address and report it and EBP
uint32_t ret = ebp[1];
- cio_printf( " ebp %08x ret %08x args", (uint32_t) ebp, ret );
+ cio_printf(" ebp %08x ret %08x args", (uint32_t)ebp, ret);
// print the requested number of function arguments
- for( uint_t i = 0; i < args; ++i ) {
- cio_printf( " [%u] %08x", i+1, ebp[2+i] );
+ for (uint_t i = 0; i < args; ++i) {
+ cio_printf(" [%u] %08x", i + 1, ebp[2 + i]);
}
- cio_putchar( '\n' );
+ cio_putchar('\n');
// follow the chain
- ebp = (uint32_t *) *ebp;
+ ebp = (uint32_t *)*ebp;
}
}
@@ -78,35 +77,35 @@ void backtrace( uint32_t *ebp, uint_t args ) {
** @param msg[in] String containing a relevant message to be printed,
** or NULL
*/
-void kpanic( const char *msg ) {
-
- cio_puts( "\n\n***** KERNEL PANIC *****\n\n" );
+void kpanic(const char *msg)
+{
+ cio_puts("\n\n***** KERNEL PANIC *****\n\n");
- if( msg ) {
- cio_printf( "%s\n", msg );
+ if (msg) {
+ cio_printf("%s\n", msg);
}
- delay( DELAY_5_SEC ); // approximately
+ delay(DELAY_5_SEC); // approximately
// dump a bunch of potentially useful information
// dump the contents of the current PCB
- pcb_dump( "Current", current, true );
+ pcb_dump("Current", current, true);
// dump the basic info about what's in the process table
ptable_dump_counts();
// dump information about the queues
- pcb_queue_dump( "R", ready, true );
- pcb_queue_dump( "W", waiting, true );
- pcb_queue_dump( "S", sleeping, true );
- pcb_queue_dump( "Z", zombie, true );
- pcb_queue_dump( "I", sioread, true );
+ pcb_queue_dump("R", ready, true);
+ pcb_queue_dump("W", waiting, true);
+ pcb_queue_dump("S", sleeping, true);
+ pcb_queue_dump("Z", zombie, true);
+ pcb_queue_dump("I", sioread, true);
// perform a stack backtrace
- backtrace( (uint32_t *) r_ebp(), 3 );
+ backtrace((uint32_t *)r_ebp(), 3);
// could dump other stuff here, too
- panic( "KERNEL PANIC" );
+ panic("KERNEL PANIC");
}
diff --git a/lib/memclr.c b/lib/memclr.c
index 490fc6d..e839382 100644
--- a/lib/memclr.c
+++ b/lib/memclr.c
@@ -21,7 +21,8 @@
** @param buf The buffer to initialize
** @param len Buffer size (in bytes)
*/
-void memclr( void *buf, register uint32_t len ) {
+void memclr(void *buf, register uint32_t len)
+{
register uint8_t *dest = buf;
/*
@@ -29,8 +30,8 @@ void memclr( void *buf, register uint32_t len ) {
** words at a time (instead of bytes).
*/
- while( len-- ) {
- *dest++ = 0;
+ while (len--) {
+ *dest++ = 0;
}
}
diff --git a/lib/memcpy.c b/lib/memcpy.c
index e5add26..020cc68 100644
--- a/lib/memcpy.c
+++ b/lib/memcpy.c
@@ -24,7 +24,8 @@
** @param src Source buffer
** @param len Buffer size (in bytes)
*/
-void memcpy( void *dst, register const void *src, register uint32_t len ) {
+void memcpy(void *dst, register const void *src, register uint32_t len)
+{
register uint8_t *dest = dst;
register const uint8_t *source = src;
@@ -33,7 +34,7 @@ void memcpy( void *dst, register const void *src, register uint32_t len ) {
** words at a time (instead of bytes).
*/
- while( len-- ) {
+ while (len--) {
*dest++ = *source++;
}
}
diff --git a/lib/memmove.c b/lib/memmove.c
new file mode 100644
index 0000000..e674c49
--- /dev/null
+++ b/lib/memmove.c
@@ -0,0 +1,49 @@
+/**
+** @file memmove.c
+**
+** @author Numerous CSCI-452 classes
+**
+** @brief C implementations of common library functions
+*/
+
+#ifndef MEMMOVE_SRC_INC
+#define MEMMOVE_SRC_INC
+
+#include <common.h>
+
+#include <lib.h>
+
+/**
+** memmove(dst,src,len)
+**
+** Copy a block from one place to another. Deals with overlapping
+** buffers.
+**
+** @param dst Destination buffer
+** @param src Source buffer
+** @param len Buffer size (in bytes)
+*/
+void memmove(void *dst, const void *src, register uint32_t len)
+{
+ register uint8_t *dest = dst;
+ register const uint8_t *source = src;
+
+ /*
+ ** We could speed this up by unrolling it and copying
+ ** words at a time (instead of bytes).
+ */
+
+ if (source < dest && (source + len) > dest) {
+ source += len;
+ dest += len;
+ while (len-- > 0) {
+ *--dest = *--source;
+ }
+ } else {
+ while (len--) {
+ *dest++ = *source++;
+ }
+ }
+}
+
+#endif
diff --git a/lib/memset.c b/lib/memset.c
index a93815c..cb378ff 100644
--- a/lib/memset.c
+++ b/lib/memset.c
@@ -22,7 +22,8 @@
** @param len Buffer size (in bytes)
** @param value Initialization value
*/
-void memset( void *buf, register uint32_t len, register uint32_t value ) {
+void memset(void *buf, register uint32_t len, register uint32_t value)
+{
register uint8_t *bp = buf;
/*
@@ -30,7 +31,7 @@ void memset( void *buf, register uint32_t len, register uint32_t value ) {
** words at a time (instead of bytes).
*/
- while( len-- ) {
+ while (len--) {
*bp++ = value;
}
}
diff --git a/lib/pad.c b/lib/pad.c
index 5220c99..03a352b 100644
--- a/lib/pad.c
+++ b/lib/pad.c
@@ -24,9 +24,10 @@
**
** NOTE: does NOT NUL-terminate the buffer
*/
-char *pad( char *dst, int extra, int padchar ) {
- while( extra > 0 ){
- *dst++ = (char) padchar;
+char *pad(char *dst, int extra, int padchar)
+{
+ while (extra > 0) {
+ *dst++ = (char)padchar;
extra -= 1;
}
return dst;
diff --git a/lib/padstr.c b/lib/padstr.c
index b83229f..5806704 100644
--- a/lib/padstr.c
+++ b/lib/padstr.c
@@ -28,31 +28,32 @@
**
** NOTE: does NOT NUL-terminate the buffer
*/
-char *padstr( char *dst, char *str, int len, int width,
- int leftadjust, int padchar ) {
+char *padstr(char *dst, char *str, int len, int width, int leftadjust,
+ int padchar)
+{
int extra;
// determine the length of the string if we need to
- if( len < 0 ){
- len = strlen( str );
+ if (len < 0) {
+ len = strlen(str);
}
// how much filler must we add?
extra = width - len;
// add filler on the left if we're not left-justifying
- if( extra > 0 && !leftadjust ){
- dst = pad( dst, extra, padchar );
+ if (extra > 0 && !leftadjust) {
+ dst = pad(dst, extra, padchar);
}
// copy the string itself
- for( int i = 0; i < len; ++i ) {
+ for (int i = 0; i < len; ++i) {
*dst++ = str[i];
}
// add filler on the right if we are left-justifying
- if( extra > 0 && leftadjust ){
- dst = pad( dst, extra, padchar );
+ if (extra > 0 && leftadjust) {
+ dst = pad(dst, extra, padchar);
}
return dst;
diff --git a/lib/sprint.c b/lib/sprint.c
index d2e0a7e..05ddfb5 100644
--- a/lib/sprint.c
+++ b/lib/sprint.c
@@ -28,9 +28,10 @@
** (parameters are pushed onto the stack in reverse order as
** 32-bit values).
*/
-void sprint( char *dst, char *fmt, ... ) {
+void sprint(char *dst, char *fmt, ...)
+{
int32_t *ap;
- char buf[ 12 ];
+ char buf[12];
char ch;
char *str;
int leftadjust;
@@ -49,16 +50,16 @@ void sprint( char *dst, char *fmt, ... ) {
** to point to the next "thing", and interpret it according
** to the format string.
*/
-
+
// get the pointer to the first "value" parameter
ap = (int *)(&fmt) + 1;
// iterate through the format string
- while( (ch = *fmt++) != '\0' ){
+ while ((ch = *fmt++) != '\0') {
/*
** Is it the start of a format code?
*/
- if( ch == '%' ){
+ if (ch == '%') {
/*
** Yes, get the padding and width options (if there).
** Alignment must come at the beginning, then fill,
@@ -68,15 +69,15 @@ void sprint( char *dst, char *fmt, ... ) {
padchar = ' ';
width = 0;
ch = *fmt++;
- if( ch == '-' ){
+ if (ch == '-') {
leftadjust = 1;
ch = *fmt++;
}
- if( ch == '0' ){
+ if (ch == '0') {
padchar = '0';
ch = *fmt++;
}
- while( ch >= '0' && ch <= '9' ){
+ while (ch >= '0' && ch <= '9') {
width *= 10;
width += ch - '0';
ch = *fmt++;
@@ -85,40 +86,38 @@ void sprint( char *dst, char *fmt, ... ) {
/*
** What data type do we have?
*/
- switch( ch ) {
-
- case 'c': // characters are passed as 32-bit values
+ switch (ch) {
+ case 'c': // characters are passed as 32-bit values
ch = *ap++;
- buf[ 0 ] = ch;
- buf[ 1 ] = '\0';
- dst = padstr( dst, buf, 1, width, leftadjust, padchar );
+ buf[0] = ch;
+ buf[1] = '\0';
+ dst = padstr(dst, buf, 1, width, leftadjust, padchar);
break;
case 'd':
- len = cvtdec( buf, *ap++ );
- dst = padstr( dst, buf, len, width, leftadjust, padchar );
+ len = cvtdec(buf, *ap++);
+ dst = padstr(dst, buf, len, width, leftadjust, padchar);
break;
case 's':
- str = (char *) (*ap++);
- dst = padstr( dst, str, -1, width, leftadjust, padchar );
+ str = (char *)(*ap++);
+ dst = padstr(dst, str, -1, width, leftadjust, padchar);
break;
case 'x':
- len = cvthex( buf, *ap++ );
- dst = padstr( dst, buf, len, width, leftadjust, padchar );
+ len = cvthex(buf, *ap++);
+ dst = padstr(dst, buf, len, width, leftadjust, padchar);
break;
case 'o':
- len = cvtoct( buf, *ap++ );
- dst = padstr( dst, buf, len, width, leftadjust, padchar );
+ len = cvtoct(buf, *ap++);
+ dst = padstr(dst, buf, len, width, leftadjust, padchar);
break;
case 'u':
- len = cvtuns( buf, *ap++ );
- dst = padstr( dst, buf, len, width, leftadjust, padchar );
+ len = cvtuns(buf, *ap++);
+ dst = padstr(dst, buf, len, width, leftadjust, padchar);
break;
-
}
} else {
// no, it's just an ordinary character
diff --git a/lib/str2int.c b/lib/str2int.c
index c0f777d..ce28a7a 100644
--- a/lib/str2int.c
+++ b/lib/str2int.c
@@ -21,31 +21,32 @@
**
** @return The converted integer
*/
-int str2int( register const char *str, register int base ) {
+int str2int(register const char *str, register int base)
+{
register int num = 0;
register char bchar = '9';
int sign = 1;
// check for leading '-'
- if( *str == '-' ) {
+ if (*str == '-') {
sign = -1;
++str;
}
- if( base != 10 ) {
+ if (base != 10) {
bchar = '0' + base - 1;
}
// iterate through the characters
- while( *str ) {
- if( *str < '0' || *str > bchar )
+ while (*str) {
+ if (*str < '0' || *str > bchar)
break;
num = num * base + *str - '0';
++str;
}
// return the converted value
- return( num * sign );
+ return (num * sign);
}
#endif
diff --git a/lib/strcat.c b/lib/strcat.c
index b0a8726..f7823bf 100644
--- a/lib/strcat.c
+++ b/lib/strcat.c
@@ -23,16 +23,17 @@
**
** NOTE: assumes dst is large enough to hold the resulting string
*/
-char *strcat( register char *dst, register const char *src ) {
+char *strcat(register char *dst, register const char *src)
+{
register char *tmp = dst;
- while( *dst ) // find the NUL
+ while (*dst) // find the NUL
++dst;
- while( (*dst++ = *src++) ) // append the src string
+ while ((*dst++ = *src++)) // append the src string
;
- return( tmp );
+ return (tmp);
}
#endif
diff --git a/lib/strcmp.c b/lib/strcmp.c
index c59f4f7..d829b95 100644
--- a/lib/strcmp.c
+++ b/lib/strcmp.c
@@ -21,12 +21,12 @@
**
** @return negative if s1 < s2, zero if equal, and positive if s1 > s2
*/
-int strcmp( register const char *s1, register const char *s2 ) {
-
- while( *s1 != 0 && (*s1 == *s2) )
+int strcmp(register const char *s1, register const char *s2)
+{
+ while (*s1 != 0 && (*s1 == *s2))
++s1, ++s2;
- return( *s1 - *s2 );
+ return (*s1 - *s2);
}
#endif
diff --git a/lib/strcpy.c b/lib/strcpy.c
index 036e4be..e2c76d7 100644
--- a/lib/strcpy.c
+++ b/lib/strcpy.c
@@ -23,13 +23,14 @@
**
** NOTE: assumes dst is large enough to hold the copied string
*/
-char *strcpy( register char *dst, register const char *src ) {
+char *strcpy(register char *dst, register const char *src)
+{
register char *tmp = dst;
- while( (*dst++ = *src++) )
+ while ((*dst++ = *src++))
;
- return( tmp );
+ return (tmp);
}
#endif
diff --git a/lib/strlen.c b/lib/strlen.c
index b41fe69..4687a8a 100644
--- a/lib/strlen.c
+++ b/lib/strlen.c
@@ -20,13 +20,14 @@
**
** @return The length of the string, or 0
*/
-uint32_t strlen( register const char *str ) {
+uint32_t strlen(register const char *str)
+{
register uint32_t len = 0;
- while( *str++ ) {
+ while (*str++) {
++len;
}
- return( len );
+ return (len);
}
#endif
diff --git a/lib/ulibc.c b/lib/ulibc.c
index f3783a4..38aa7df 100644
--- a/lib/ulibc.c
+++ b/lib/ulibc.c
@@ -50,8 +50,9 @@
**
** @returns The PID of the terminated child, or an error code
*/
-int wait( int32_t *status ) {
- return( waitpid(0,status) );
+int wait(int32_t *status)
+{
+ return (waitpid(0, status));
}
/**
@@ -66,14 +67,15 @@ int wait( int32_t *status ) {
**
** @returns PID of the new process, or an error code
*/
-int32_t spawn( uint_t what, char **args ) {
+int32_t spawn(uint_t what, char **args)
+{
int32_t pid;
char buf[256];
pid = fork();
- if( pid != 0 ) {
+ if (pid != 0) {
// failure, or we are the parent
- return( pid );
+ return (pid);
}
// we are the child
@@ -81,15 +83,15 @@ int32_t spawn( uint_t what, char **args ) {
// child inherits parent's priority level
- exec( what, args );
+ exec(what, args);
// uh-oh....
- sprint( buf, "Child %d exec() #%u failed\n", pid, what );
- cwrites( buf );
+ sprint(buf, "Child %d exec() #%u failed\n", pid, what);
+ cwrites(buf);
- exit( EXIT_FAILURE );
- return( 0 ); // shut the compiler up
+ exit(EXIT_FAILURE);
+ return (0); // shut the compiler up
}
/**
@@ -99,8 +101,9 @@ int32_t spawn( uint_t what, char **args ) {
**
** @returns The return value from calling write()
*/
-int cwritech( char ch ) {
- return( write(CHAN_CIO,&ch,1) );
+int cwritech(char ch)
+{
+ return (write(CHAN_CIO, &ch, 1));
}
/**
@@ -109,9 +112,10 @@ int cwritech( char ch ) {
** @param str The string to write
**
*/
-int cwrites( const char *str ) {
+int cwrites(const char *str)
+{
int len = strlen(str);
- return( write(CHAN_CIO,str,len) );
+ return (write(CHAN_CIO, str, len));
}
/**
@@ -122,8 +126,9 @@ int cwrites( const char *str ) {
**
** @returns The return value from calling write()
*/
-int cwrite( const char *buf, uint32_t size ) {
- return( write(CHAN_CIO,buf,size) );
+int cwrite(const char *buf, uint32_t size)
+{
+ return (write(CHAN_CIO, buf, size));
}
/**
@@ -133,8 +138,9 @@ int cwrite( const char *buf, uint32_t size ) {
**
** @returns The return value from calling write()
*/
-int swritech( char ch ) {
- return( write(CHAN_SIO,&ch,1) );
+int swritech(char ch)
+{
+ return (write(CHAN_SIO, &ch, 1));
}
/**
@@ -144,9 +150,10 @@ int swritech( char ch ) {
**
** @returns The return value from calling write()
*/
-int swrites( const char *str ) {
+int swrites(const char *str)
+{
int len = strlen(str);
- return( write(CHAN_SIO,str,len) );
+ return (write(CHAN_SIO, str, len));
}
/**
@@ -157,6 +164,7 @@ int swrites( const char *str ) {
**
** @returns The return value from calling write()
*/
-int swrite( const char *buf, uint32_t size ) {
- return( write(CHAN_SIO,buf,size) );
+int swrite(const char *buf, uint32_t size)
+{
+ return (write(CHAN_SIO, buf, size));
}