Replace userland perror calls.

This commit is contained in:
Jonas 'Sortie' Termansen 2015-06-10 23:24:25 +02:00
parent f1571ebaf4
commit 00f3e97cf7
6 changed files with 17 additions and 8 deletions

View File

@ -20,6 +20,7 @@
*******************************************************************************/
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -39,11 +40,13 @@ static int uptime(uintmax_t* usecs)
int main(int /*argc*/, char* /*argv*/[])
{
pid_t slavepid = fork();
if ( slavepid < 0 ) { perror("fork"); return 1; }
if ( slavepid < 0 )
err(1, "fork");
if ( slavepid == 0 ) { while ( true ) { usleep(0); } exit(0); }
uintmax_t start;
if ( uptime(&start) ) { perror("uptime"); return 1; }
if ( uptime(&start) )
err(1, "uptime");
uintmax_t end = start + 1ULL * 1000ULL * 1000ULL; // 1 second
size_t count = 0;
uintmax_t now;

View File

@ -21,6 +21,7 @@
*******************************************************************************/
#include <err.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
@ -37,7 +38,8 @@ static int uptime(uintmax_t* usecs)
int main(int /*argc*/, char* /*argv*/[])
{
uintmax_t start;
if ( uptime(&start) ) { perror("uptime"); return 1; }
if ( uptime(&start) )
err(1, "uptime");
uintmax_t end = start + 1ULL * 1000ULL * 1000ULL; // 1 second
size_t count = 0;
uintmax_t now;

View File

@ -62,7 +62,7 @@ bool Find(int dirfd, const char* relpath, const char* path, int types)
if ( types & TYPE_DIR )
printf("%s\n", path);
DIR* dir = fdopendir(fd);
if ( !dir ) { perror("fdopendir"); close(fd); return false; }
if ( !dir ) { error(0, errno, "fdopendir"); close(fd); return false; }
struct dirent* entry;
while ( (entry = readdir(dir)) )
{

View File

@ -64,7 +64,8 @@ int main(int argc, char* argv[])
}
size_t bufsize = 32;
char* buf = (char*) malloc(bufsize);
if ( !buf ) { perror("malloc"); return 1; }
if ( !buf )
error(1, errno, "malloc");
for ( int i = 1; i < argc; i++ )
{
retry:
@ -80,7 +81,8 @@ retry:
if ( ret )
{
buf = (char*) realloc(buf, ret);
if ( !buf ) { perror("realloc"); return 1; }
if ( !buf )
error(1, errno, "realloc");
bufsize = ret;
goto retry;
}

View File

@ -396,7 +396,7 @@ int ls(const char* path)
{
if ( errno == ENOTDIR )
return handle_entry_internal(path, path, DT_UNKNOWN);
perror(path);
error(0, errno, "%s", path);
ret = 2;
goto cleanup_entries;
}

View File

@ -20,6 +20,7 @@
*******************************************************************************/
#include <err.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
@ -66,7 +67,8 @@ int main(int /*argc*/, char* /*argv*/[])
{
size_t memused = 0;
size_t memtotal = 0;
if ( memstat(&memused, &memtotal) ) { perror("memstat"); return 1; }
if ( memstat(&memused, &memtotal) )
err(1, "memstat");
printf("memory usage: ");
printbytes(memused);