Browse files

standard library

  • Loading branch information...
1 parent 42784ba commit c626449bcf1cdf08081e5e58731238bd82fcfcad @shiva committed Oct 30, 2011
View
13 README
@@ -1,5 +1,18 @@
+Summary of Contents
+===================
+
+./th-stor - Thread storage
+./th-stor/src
+./th-stor/build
+./th-stor/include
+./build - build everything
+./locks - Examples for thread locking
+./fwc_stdlib - standard library (based on Linux Programming Interface stdlib)
+ provides basic types, error functions, etc
+
Stuff written for fun
+=====================
1. experiments with thread local storage
a. thread specific storage
View
19 build/CMakeLists.txt
@@ -0,0 +1,19 @@
+#Specify the version being used aswell as the language
+cmake_minimum_required(VERSION 2.6)
+#Name your project here
+project(funwithc)
+
+#Sends the -std=c99 flag to the gcc compiler
+add_definitions(-std=c99)
+
+set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
+set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
+
+include_directories("${PROJECT_SOURCE_DIR}/../fwc_stdlib")
+add_subdirectory("${PROJECT_SOURCE_DIR}/../fwc_stdlib")
+
+#This tells CMake to fib.c and name it fibonacci
+#add_executable(fibonacci fib.c)
+
+
+
View
16 fwc_stdlib/CMakeLists.txt
@@ -0,0 +1,16 @@
+set(FWC_SOURCES
+ error_functions.c
+)
+
+
+add_library(fwc_stdlib SHARED ${FWC_SOURCES})
+add_library(fwc_stdlib-static STATIC ${FWC_SOURCES})
+
+set_target_properties(fwc_stdlib-static PROPERTIES OUTPUT_NAME "fwc_stdlib")
+# Now the library target "fwc_stdlib-static" will be named
+# "fwc_stdlib.lib" with MS tools. This conflicts with the "fwc_stdlib.lib"
+# import library corresponding to "fwc_stdlib.dll",
+# so we add a "lib" prefix (which is default on other platforms anyway):
+set_target_properties(fwc_stdlib-static PROPERTIES PREFIX "lib")
+
+
View
168 fwc_stdlib/Makefile
@@ -0,0 +1,168 @@
+# CMAKE generated file: DO NOT EDIT!
+# Generated by "Unix Makefiles" Generator, CMake Version 2.8
+
+# Default target executed when no arguments are given to make.
+default_target: all
+.PHONY : default_target
+
+#=============================================================================
+# Special targets provided by cmake.
+
+# Disable implicit rules so canoncical targets will work.
+.SUFFIXES:
+
+# Remove some rules from gmake that .SUFFIXES does not remove.
+SUFFIXES =
+
+.SUFFIXES: .hpux_make_needs_suffix_list
+
+# Suppress display of executed commands.
+$(VERBOSE).SILENT:
+
+# A target that is always out of date.
+cmake_force:
+.PHONY : cmake_force
+
+#=============================================================================
+# Set environment variables for the build.
+
+# The shell in which to execute make rules.
+SHELL = /bin/sh
+
+# The CMake executable.
+CMAKE_COMMAND = /usr/bin/cmake
+
+# The command to remove a file.
+RM = /usr/bin/cmake -E remove -f
+
+# The top-level source directory on which CMake was run.
+CMAKE_SOURCE_DIR = /home/shiva/src/projects/fun.git/fun/fwc_stdlib
+
+# The top-level build directory on which CMake was run.
+CMAKE_BINARY_DIR = /home/shiva/src/projects/fun.git/fun/fwc_stdlib
+
+#=============================================================================
+# Targets provided globally by CMake.
+
+# Special rule for the target edit_cache
+edit_cache:
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running interactive CMake command-line interface..."
+ /usr/bin/cmake -i .
+.PHONY : edit_cache
+
+# Special rule for the target edit_cache
+edit_cache/fast: edit_cache
+.PHONY : edit_cache/fast
+
+# Special rule for the target rebuild_cache
+rebuild_cache:
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
+ /usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
+.PHONY : rebuild_cache
+
+# Special rule for the target rebuild_cache
+rebuild_cache/fast: rebuild_cache
+.PHONY : rebuild_cache/fast
+
+# The main all target
+all: cmake_check_build_system
+ $(CMAKE_COMMAND) -E cmake_progress_start /home/shiva/src/projects/fun.git/fun/fwc_stdlib/CMakeFiles /home/shiva/src/projects/fun.git/fun/fwc_stdlib/CMakeFiles/progress.marks
+ $(MAKE) -f CMakeFiles/Makefile2 all
+ $(CMAKE_COMMAND) -E cmake_progress_start /home/shiva/src/projects/fun.git/fun/fwc_stdlib/CMakeFiles 0
+.PHONY : all
+
+# The main clean target
+clean:
+ $(MAKE) -f CMakeFiles/Makefile2 clean
+.PHONY : clean
+
+# The main clean target
+clean/fast: clean
+.PHONY : clean/fast
+
+# Prepare targets for installation.
+preinstall: all
+ $(MAKE) -f CMakeFiles/Makefile2 preinstall
+.PHONY : preinstall
+
+# Prepare targets for installation.
+preinstall/fast:
+ $(MAKE) -f CMakeFiles/Makefile2 preinstall
+.PHONY : preinstall/fast
+
+# clear depends
+depend:
+ $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
+.PHONY : depend
+
+#=============================================================================
+# Target rules for targets named fwc_stdlib
+
+# Build rule for target.
+fwc_stdlib: cmake_check_build_system
+ $(MAKE) -f CMakeFiles/Makefile2 fwc_stdlib
+.PHONY : fwc_stdlib
+
+# fast build rule for target.
+fwc_stdlib/fast:
+ $(MAKE) -f CMakeFiles/fwc_stdlib.dir/build.make CMakeFiles/fwc_stdlib.dir/build
+.PHONY : fwc_stdlib/fast
+
+#=============================================================================
+# Target rules for targets named fwc_stdlib-static
+
+# Build rule for target.
+fwc_stdlib-static: cmake_check_build_system
+ $(MAKE) -f CMakeFiles/Makefile2 fwc_stdlib-static
+.PHONY : fwc_stdlib-static
+
+# fast build rule for target.
+fwc_stdlib-static/fast:
+ $(MAKE) -f CMakeFiles/fwc_stdlib-static.dir/build.make CMakeFiles/fwc_stdlib-static.dir/build
+.PHONY : fwc_stdlib-static/fast
+
+# target to build an object file
+error_functions.o:
+ $(MAKE) -f CMakeFiles/fwc_stdlib.dir/build.make CMakeFiles/fwc_stdlib.dir/error_functions.o
+ $(MAKE) -f CMakeFiles/fwc_stdlib-static.dir/build.make CMakeFiles/fwc_stdlib-static.dir/error_functions.o
+.PHONY : error_functions.o
+
+# target to preprocess a source file
+error_functions.i:
+ $(MAKE) -f CMakeFiles/fwc_stdlib.dir/build.make CMakeFiles/fwc_stdlib.dir/error_functions.i
+ $(MAKE) -f CMakeFiles/fwc_stdlib-static.dir/build.make CMakeFiles/fwc_stdlib-static.dir/error_functions.i
+.PHONY : error_functions.i
+
+# target to generate assembly for a file
+error_functions.s:
+ $(MAKE) -f CMakeFiles/fwc_stdlib.dir/build.make CMakeFiles/fwc_stdlib.dir/error_functions.s
+ $(MAKE) -f CMakeFiles/fwc_stdlib-static.dir/build.make CMakeFiles/fwc_stdlib-static.dir/error_functions.s
+.PHONY : error_functions.s
+
+# Help Target
+help:
+ @echo "The following are some of the valid targets for this Makefile:"
+ @echo "... all (the default if no target is provided)"
+ @echo "... clean"
+ @echo "... depend"
+ @echo "... edit_cache"
+ @echo "... fwc_stdlib"
+ @echo "... fwc_stdlib-static"
+ @echo "... rebuild_cache"
+ @echo "... error_functions.o"
+ @echo "... error_functions.i"
+ @echo "... error_functions.s"
+.PHONY : help
+
+
+
+#=============================================================================
+# Special targets to cleanup operation of make.
+
+# Special rule to run CMake to check the build system integrity.
+# No rule that depends on this can have commands that come from listfiles
+# because they might be regenerated.
+cmake_check_build_system:
+ $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
+.PHONY : cmake_check_build_system
+
View
44 fwc_stdlib/cmake_install.cmake
@@ -0,0 +1,44 @@
+# Install script for directory: /home/shiva/src/projects/fun.git/fun/fwc_stdlib
+
+# Set the install prefix
+IF(NOT DEFINED CMAKE_INSTALL_PREFIX)
+ SET(CMAKE_INSTALL_PREFIX "/usr/local")
+ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)
+STRING(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
+
+# Set the install configuration name.
+IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
+ IF(BUILD_TYPE)
+ STRING(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
+ CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
+ ELSE(BUILD_TYPE)
+ SET(CMAKE_INSTALL_CONFIG_NAME "")
+ ENDIF(BUILD_TYPE)
+ MESSAGE(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
+ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
+
+# Set the component getting installed.
+IF(NOT CMAKE_INSTALL_COMPONENT)
+ IF(COMPONENT)
+ MESSAGE(STATUS "Install component: \"${COMPONENT}\"")
+ SET(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
+ ELSE(COMPONENT)
+ SET(CMAKE_INSTALL_COMPONENT)
+ ENDIF(COMPONENT)
+ENDIF(NOT CMAKE_INSTALL_COMPONENT)
+
+# Install shared libraries without execute permission?
+IF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
+ SET(CMAKE_INSTALL_SO_NO_EXE "1")
+ENDIF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
+
+IF(CMAKE_INSTALL_COMPONENT)
+ SET(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt")
+ELSE(CMAKE_INSTALL_COMPONENT)
+ SET(CMAKE_INSTALL_MANIFEST "install_manifest.txt")
+ENDIF(CMAKE_INSTALL_COMPONENT)
+
+FILE(WRITE "/home/shiva/src/projects/fun.git/fun/fwc_stdlib/${CMAKE_INSTALL_MANIFEST}" "")
+FOREACH(file ${CMAKE_INSTALL_MANIFEST_FILES})
+ FILE(APPEND "/home/shiva/src/projects/fun.git/fun/fwc_stdlib/${CMAKE_INSTALL_MANIFEST}" "${file}\n")
+ENDFOREACH(file)
View
30 fwc_stdlib/ename.c.inc
@@ -0,0 +1,30 @@
+static char *ename[] = {
+/* 0 */ "",
+/* 1 */ "EPERM", "ENOENT", "ESRCH", "EINTR", "EIO", "ENXIO", "E2BIG",
+/* 8 */ "ENOEXEC", "EBADF", "ECHILD", "EAGAIN/EWOULDBLOCK", "ENOMEM",
+/* 13 */ "EACCES", "EFAULT", "ENOTBLK", "EBUSY", "EEXIST", "EXDEV",
+/* 19 */ "ENODEV", "ENOTDIR", "EISDIR", "EINVAL", "ENFILE", "EMFILE",
+/* 25 */ "ENOTTY", "ETXTBSY", "EFBIG", "ENOSPC", "ESPIPE", "EROFS",
+/* 31 */ "EMLINK", "EPIPE", "EDOM", "ERANGE", "EDEADLK/EDEADLOCK",
+/* 36 */ "ENAMETOOLONG", "ENOLCK", "ENOSYS", "ENOTEMPTY", "ELOOP", "",
+/* 42 */ "ENOMSG", "EIDRM", "ECHRNG", "EL2NSYNC", "EL3HLT", "EL3RST",
+/* 48 */ "ELNRNG", "EUNATCH", "ENOCSI", "EL2HLT", "EBADE", "EBADR",
+/* 54 */ "EXFULL", "ENOANO", "EBADRQC", "EBADSLT", "", "EBFONT", "ENOSTR",
+/* 61 */ "ENODATA", "ETIME", "ENOSR", "ENONET", "ENOPKG", "EREMOTE",
+/* 67 */ "ENOLINK", "EADV", "ESRMNT", "ECOMM", "EPROTO", "EMULTIHOP",
+/* 73 */ "EDOTDOT", "EBADMSG", "EOVERFLOW", "ENOTUNIQ", "EBADFD",
+/* 78 */ "EREMCHG", "ELIBACC", "ELIBBAD", "ELIBSCN", "ELIBMAX",
+/* 83 */ "ELIBEXEC", "EILSEQ", "ERESTART", "ESTRPIPE", "EUSERS",
+/* 88 */ "ENOTSOCK", "EDESTADDRREQ", "EMSGSIZE", "EPROTOTYPE",
+/* 92 */ "ENOPROTOOPT", "EPROTONOSUPPORT", "ESOCKTNOSUPPORT",
+/* 95 */ "EOPNOTSUPP/ENOTSUP", "EPFNOSUPPORT", "EAFNOSUPPORT",
+/* 98 */ "EADDRINUSE", "EADDRNOTAVAIL", "ENETDOWN", "ENETUNREACH",
+/* 102 */ "ENETRESET", "ECONNABORTED", "ECONNRESET", "ENOBUFS", "EISCONN",
+/* 107 */ "ENOTCONN", "ESHUTDOWN", "ETOOMANYREFS", "ETIMEDOUT",
+/* 111 */ "ECONNREFUSED", "EHOSTDOWN", "EHOSTUNREACH", "EALREADY",
+/* 115 */ "EINPROGRESS", "ESTALE", "EUCLEAN", "ENOTNAM", "ENAVAIL",
+/* 120 */ "EISNAM", "EREMOTEIO", "EDQUOT", "ENOMEDIUM", "EMEDIUMTYPE",
+/* 125 */ "ECANCELED", "ENOKEY", "EKEYEXPIRED", "EKEYREVOKED",
+/* 129 */ "EKEYREJECTED", "EOWNERDEAD", "ENOTRECOVERABLE", "ERFKILL"
+};
+#define MAX_ENAME 132
View
133 fwc_stdlib/error_functions.c
@@ -0,0 +1,133 @@
+#include <stdarg.h>
+#include "error_functions.h"
+#include "funwc_hdr.h"
+#include "ename.c.inc" /* Defines ename and MAX_ENAME */
+
+#ifdef __GNUC__
+__attribute__ ((__noreturn__))
+#endif
+
+static void
+terminate(Boolean useExit3)
+{
+ char *s;
+
+ /* Dump core if EF_DUMPCORE environment variable is defined
+ and is a nonempty string; otherwise call exit(3) or _exit(2),
+ depending on the value of 'useExit3'. */
+ s = getenv("EF_DUMPCORE");
+ if (s != NULL && *s != '\0')
+ abort();
+ else if (useExit3)
+ exit(EXIT_FAILURE);
+ else
+ _exit(EXIT_FAILURE);
+}
+
+static void
+outputError(Boolean useErr, int err, Boolean flushStdout,
+ const char *format, va_list ap)
+{
+#define BUF_SIZE 500
+ char buf[BUF_SIZE], userMsg[BUF_SIZE], errText[BUF_SIZE];
+
+ vsnprintf(userMsg, BUF_SIZE, format, ap);
+
+ if (useErr) {
+ snprintf(errText, BUF_SIZE, " [%s %s]",
+ (err > 0 && err <= MAX_ENAME) ?
+ ename[err] : "?UNKNOWN?", strerror(err));
+ } else {
+ snprintf(errText, BUF_SIZE, ":");
+ }
+
+ snprintf(buf, BUF_SIZE, "ERROR%s %s\n", errText, userMsg);
+
+ if (flushStdout)
+ fflush(stdout); /* Flush any pending stdout */
+ fputs(buf, stderr);
+ fflush(stderr); /* In case stderr is not line-buffered */
+}
+
+void
+errMsg(const char *format, ...)
+{
+ va_list argList;
+ int savedErrno;
+
+ savedErrno = errno; /* In case we change it here */
+
+ va_start(argList, format);
+ outputError(TRUE, errno, TRUE, format, argList);
+ va_end(argList);
+
+ errno = savedErrno;
+}
+
+void
+errExit(const char *format, ...)
+{
+ va_list argList;
+
+ va_start(argList, format);
+ outputError(TRUE, errno, TRUE, format, argList);
+ va_end(argList);
+
+ terminate(TRUE);
+}
+
+void
+err_exit(const char *format, ...)
+{
+ va_list argList;
+
+ va_start(argList, format);
+ outputError(TRUE, errno, FALSE, format, argList);
+ va_end(argList);
+
+ terminate(FALSE);
+}
+
+void
+fatal(const char *format, ...)
+{
+ va_list argList;
+
+ va_start(argList, format);
+ outputError(FALSE, 0, TRUE, format, argList);
+ va_end(argList);
+
+ terminate(TRUE);
+}
+
+void
+usageErr(const char *format, ...)
+{
+ va_list argList;
+
+ fflush(stdout); /* Flush any pending stdout */
+
+ fprintf(stderr, "Usage: ");
+ va_start(argList, format);
+ vfprintf(stderr, format, argList);
+ va_end(argList);
+
+ fflush(stderr); /* In case stderr is not line-buffered */
+ exit(EXIT_FAILURE);
+}
+
+void
+cmdLineErr(const char *format, ...)
+{
+ va_list argList;
+
+ fflush(stdout); /* Flush any pending stdout */
+
+ fprintf(stderr, "Command-line usage error: ");
+ va_start(argList, format);
+ vfprintf(stderr, format, argList);
+ va_end(argList);
+
+ fflush(stderr); /* In case stderr is not line-buffered */
+ exit(EXIT_FAILURE);
+}
View
6 lib/error_functions.h → fwc_stdlib/error_functions.h
@@ -6,8 +6,10 @@ void errMsg(const char *format, ...);
#ifdef __GNUC__
/* This macro stops 'gcc -Wall' complaining that "control reaches
-end of non-void function" if we use the following functions to terminate main() or some other non-void function. */
-#define NORETURN __attribute__ ((__noreturn__)) #else
+ end of non-void function" if we use the following functions to
+ terminate main() or some other non-void function. */
+#define NORETURN __attribute__ ((__noreturn__))
+#else
#define NORETURN
#endif
View
5 lib/funwc_hdr.h → fwc_stdlib/funwc_hdr.h
@@ -9,6 +9,11 @@
#include <errno.h> /* Declares errno and defines error constants */
#include <string.h> /* Commonly used string-handling functions */
+#include "get_num.h" /* Declares our functions for handling numeric
+ arguments (getInt(), getLong()) */
+
+#include "error_functions.h" /* Declares our error-handling functions */
+
typedef enum { FALSE, TRUE } Boolean;
#define min(m,n) ((m) < (n) ? (m) : (n))
View
68 fwc_stdlib/get_num.c
@@ -0,0 +1,68 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <errno.h>
+#include "get_num.h"
+
+static void
+gnFail(const char *fname, const char *msg, const char *arg, const char *name)
+{
+ fprintf(stderr, "%s error", fname);
+
+ if (name != NULL)
+ fprintf(stderr, " (in %s)", name);
+
+ fprintf(stderr, ": %s\n", msg);
+ if (arg != NULL && *arg != '\0')
+ fprintf(stderr, " offending text: %s\n", arg);
+
+ exit(EXIT_FAILURE);
+}
+
+static long
+getNum(const char *fname, const char *arg, int flags, const char *name)
+{
+ long res;
+ char *endptr;
+ int base;
+
+ if (arg == NULL || *arg == '\0')
+ gnFail(fname, "null or empty string", arg, name);
+
+ base = (flags & GN_ANY_BASE) ? 0 : (
+ (flags & GN_BASE_8) ? 8 : (
+ (flags & GN_BASE_16) ? 16 : 10
+ )
+ );
+
+ errno = 0;
+ res = strtol(arg, &endptr, base);
+ if (errno != 0)
+ gnFail(fname, "strtol() failed", arg, name);
+ if (*endptr != '\0')
+ gnFail(fname, "nonnumeric characters", arg, name);
+ if ((flags & GN_NONNEG) && res < 0)
+ gnFail(fname, "negative value not allowed", arg, name);
+ if ((flags & GN_GT_0) && res <= 0)
+ gnFail(fname, "value must be > 0", arg, name);
+ return res;
+}
+
+long
+getLong(const char *arg, int flags, const char *name)
+{
+ return getNum("getLong", arg, flags, name);
+}
+
+int
+getInt(const char *arg, int flags, const char *name)
+{
+ long res;
+
+ res = getNum("getInt", arg, flags, name);
+ if (res > INT_MAX || res < INT_MIN)
+ gnFail("getInt", "integer out of range", arg, name);
+
+ return (int) res;
+}
View
17 fwc_stdlib/get_num.h
@@ -0,0 +1,17 @@
+#ifndef GET_NUM_H
+#define GET_NUM_H
+
+#define GN_NONNEG 01 /* Value must be >= 0 */
+#define GN_GT_0 02 /* Value must be > 0 */
+
+
+/* By default, integers are decimal */
+#define GN_ANY_BASE 0100 /* Can use any base - like strtol(3) */
+#define GN_BASE_8 0200 /* Value is expressed in octal */
+#define GN_BASE_16 0400 /* Value is expressed in hexadecimal */
+
+long getLong(const char *arg, int flags, const char *name);
+
+int getInt(const char *arg, int flags, const char *name);
+
+#endif /* GET_NUM_H */
View
105 lib/error_functions.c
@@ -1,105 +0,0 @@
-#include <stdarg.h>
-#include "error_functions.h"
-#include "tlpi_hdr.h"
-#include "ename.c.inc"
-#ifdef __GNUC__
-__attribute__ ((__noreturn__)) #endif
-static void
-terminate(Boolean useExit3)
-{
-char *s;
-/* Defines ename and MAX_ENAME */
-/* Dump core if EF_DUMPCORE environment variable is defined and is a nonempty string; otherwise call exit(3) or _exit(2), depending on the value of 'useExit3'. */
- s = getenv("EF_DUMPCORE");
- if (s != NULL && *s != '\0')
- abort();
- else if (useExit3)
- exit(EXIT_FAILURE);
- else
- _exit(EXIT_FAILURE);
-}
-54 Chapter 3
-static void
-outputError(Boolean useErr, int err, Boolean flushStdout,
- const char *format, va_list ap)
-{
-#define BUF_SIZE 500
-char buf[BUF_SIZE], userMsg[BUF_SIZE], errText[BUF_SIZE];
-vsnprintf(userMsg, BUF_SIZE, format, ap);
-if (useErr)
-snprintf(errText, BUF_SIZE, " [%s %s]",
-(err > 0 && err <= MAX_ENAME) ? ename[err] : "?UNKNOWN?", strerror(err));
-else
-snprintf(errText, BUF_SIZE, ":");
-snprintf(buf, BUF_SIZE, "ERROR%s %s\n", errText, userMsg);
-}
-if (flushStdout)
- fflush(stdout);
-fputs(buf, stderr);
-fflush(stderr);
-/* Flush any pending stdout */
-/* In case stderr is not line-buffered */
-void
-errMsg(const char *format, ...)
-{
- va_list argList;
- int savedErrno;
-savedErrno = errno; /* In case we change it here */
-va_start(argList, format);
-outputError(TRUE, errno, TRUE, format, argList); va_end(argList);
- errno = savedErrno;
-}
-void
-errExit(const char *format, ...)
-{
- va_list argList;
-va_start(argList, format);
-outputError(TRUE, errno, TRUE, format, argList); va_end(argList);
- terminate(TRUE);
-}
-System Programming Concepts 55
-56 Chapter 3
-void
-err_exit(const char *format, ...) {
- va_list argList;
- va_start(argList, format);
- outputError(TRUE,
- va_end(argList);
- terminate(FALSE);
-}
-void
-errExitEN(int errnum,
-{
- va_list argList;
-errno, FALSE, format, argList);
-const char *format, ...)
-va_start(argList, format);
-outputError(TRUE, errnum, TRUE, format, argList); va_end(argList);
- terminate(TRUE);
-}
-void
-fatal(const char *format, ...)
-{
- va_list argList;
-va_start(argList, format);
-outputError(FALSE, 0, TRUE, format, argList); va_end(argList);
- terminate(TRUE);
-}
-void
-usageErr(const char *format, ...) {
-va_list argList;
-fflush(stdout); /* Flush any pending stdout */
-fprintf(stderr, "Usage: "); va_start(argList, format); vfprintf(stderr, format, argList); va_end(argList);
-fflush(stderr); /* In case stderr is not line-buffered */
- exit(EXIT_FAILURE);
-}
-void
-cmdLineErr(const char *format, ...)
-{
-va_list argList;
-fflush(stdout); /* Flush any pending stdout */
-fprintf(stderr, "Command-line usage error: "); va_start(argList, format);
-vfprintf(stderr, format, argList); va_end(argList);
-fflush(stderr); /* In case stderr is not line-buffered */
- exit(EXIT_FAILURE);
-}

0 comments on commit c626449

Please sign in to comment.