Scott M. Mcdermott

UNIX Systems & Network Administrator
available for contract or salaried positions

util.c

/*
 * Common utility functions.
 */

#define _GNU_SOURCE

#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>

#include "util.h"

^L

void
xchdir (const char *dir)
{
        if (chdir(dir) == -1) {
                fprintf(stderr, "%s: chdir: %s: %s\n",
                        progname, dir, strerror(errno));
                exit(EXIT_FAILURE);
        }
}

int
xopen (const char *filename,
       int flags)
{
        int fd;

        if ((fd = open(filename, flags)) == -1) {
                fprintf(stderr, "%s: open: %s: %s\n",
                        progname, filename, strerror(errno));
                exit(EXIT_FAILURE);
        }

        return fd;
}