Browse Source

Initial commit

master
Damien Goutte-Gattat 9 years ago
commit
98d937e128
  1. 22
      .gitignore
  2. 3
      Makefile.am
  3. 33
      configure.ac
  4. 5
      lib/Makefile.am
  5. 108
      lib/compat.h
  6. 0
      lib/dummy.c
  7. 110
      lib/err.c
  8. 48
      lib/err.compat.h
  9. 31
      lib/progname.c
  10. 16
      m4/notch.m4
  11. 7
      src/Makefile.am
  12. 93
      src/wait4.c

22
.gitignore

@ -0,0 +1,22 @@
# Autotools-generated files
Makefile.in
Makefile
autom4te.cache
config.h.in*
config.h
config.log
config.status
config
configure
stamp-*
# Autoconf macros files
*.m4
# Built files
src/*.o
src/.deps
src/wait4
lib/*.o
lib/.deps
lib/lib*.a

3
Makefile.am

@ -0,0 +1,3 @@
SUBDIRS = lib src
ACLOCAL_AMFLAGS = -I m4 --install

33
configure.ac

@ -0,0 +1,33 @@
dnl Configure template for the wait4 package
AC_INIT([wait4], [0.1.0],
[dgouttegattat@incenp.org])
AC_CONFIG_SRCDIR([configure.ac])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_AUX_DIR([config])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_LIBOBJ_DIR([lib])
AC_USE_SYSTEM_EXTENSIONS
AM_INIT_AUTOMAKE([foreign])
dnl Check for development tools
AC_PROG_CC
AC_PROG_RANLIB
AC_PROG_INSTALL
dnl Check for some non-ubituitous functions
ICP_CHECK_NOTCH_FUNCS
dnl Output files
AC_CONFIG_FILES([Makefile lib/Makefile src/Makefile])
AC_OUTPUT
dnl Summary
echo "
${PACKAGE_NAME} version ${PACKAGE_VERSION}
Configuration complete
Prefix: '${prefix}'
Compiler: '${CC} ${CFLAGS} ${CPPFLAGS}'
"

5
lib/Makefile.am

@ -0,0 +1,5 @@
noinst_LIBRARIES = libwait4.a
libwait4_a_SOURCES = err.compat.h compat.h dummy.c
libwait4_a_LIBADD = $(LIBOBJS)

108
lib/compat.h

@ -0,0 +1,108 @@
/*
* compat - Incenp.org Notch Library: header for missing functions
* Copyright (C) 2011 Damien Goutte-Gattat
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ICP20110203_COMPAT_H
#define ICP20110203_COMPAT_H
#ifdef __cpluscplus
extern "C" {
#endif
#ifndef HAVE_ASPRINTF
#include <stdarg.h>
int
asprintf(char **, const char *, ...);
int
vasprintf(char **, const char *, va_list);
#endif /* ! HAVE_ASPRINTF */
#ifndef HAVE_GETDELIM
#include <stdio.h>
#include <stdlib.h>
ssize_t
getdelim(char **, size_t *, int, FILE *);
#define getline(l,n,f) getdelim((l), (n), '\n', (f))
#endif /* ! HAVE_GETDELIM */
#ifndef HAVE_GETSUBOPT
int
getsubopt(char **, char *const *, char **);
#endif /* ! HAVE_GETSUBOPT */
#ifndef HAVE_STRCHRNUL
char *
strchrnul(const char *, int);
#endif /* ! HAVE_STRCHRNUL */
#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
/*
* The GNU C library, combined with the GNU linker, automatically
* stores the program name into the global variable
* `program_invocation_short_name'. So `setprogname()' can be defined
* to nothing and `getprogname()' can be aliased to that variable.
*/
#include <errno.h>
#define setprogname(a)
#define getprogname() program_invocation_short_name
#else
/*
* If the above-mentioned variable is not available, check for the
* BSD functions `getprogname()' and `setprogname()', and provide our
* own implementation if they are missing.
*/
#ifndef HAVE_SETPROGNAME
void
setprogname(const char *);
#endif
#ifndef HAVE_GETPROGNAME
const char *
setprogname(void);
#endif
#endif /* ! HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME */
#ifdef __cplusplus
}
#endif
#endif /* !ICP20110203_COMPAT_H */

0
lib/dummy.c

110
lib/err.c

@ -0,0 +1,110 @@
/*
* err - Incenp.org Notch Library: (v)(err|warn)(x) replacement
* Copyright (C) 2011 Damien Goutte-Gattat
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <stdarg.h>
#define ERR_EXIT_ON_ERROR 0x01
#define ERR_PRINT_ERRNO 0x02
const char *getprogname(void);
static void
do_error(int opt, int eval, const char *fmt, va_list ap)
{
fprintf(stderr, "%s: ", getprogname());
if ( fmt )
vfprintf(stderr, fmt, ap);
if ( opt & ERR_PRINT_ERRNO )
fprintf(stderr, ": %s", strerror(errno));
fputc('\n', stderr);
if ( opt & ERR_EXIT_ON_ERROR )
exit(eval);
}
void
err(int eval, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
do_error(ERR_EXIT_ON_ERROR | ERR_PRINT_ERRNO, eval, fmt, ap);
va_end(ap);
}
void
errx(int eval, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
do_error(ERR_EXIT_ON_ERROR, eval, fmt, ap);
va_end(ap);
}
void
verr(int eval, const char *fmt, va_list ap)
{
do_error(ERR_EXIT_ON_ERROR | ERR_PRINT_ERRNO, eval, fmt, ap);
}
void
verrx(int eval, const char *fmt, va_list ap)
{
do_error(ERR_EXIT_ON_ERROR, eval, fmt, ap);
}
void
warn(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
do_error(ERR_PRINT_ERRNO, 0, fmt, ap);
va_end(ap);
}
void
warnx(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
do_error(0, 0, fmt, ap);
va_end(ap);
}
void
vwarn(const char *fmt, va_list ap)
{
do_error(ERR_PRINT_ERRNO, 0, fmt, ap);
}
void
vwarnx(const char *fmt, va_list ap)
{
do_error(0, 0, fmt, ap);
}

48
lib/err.compat.h

@ -0,0 +1,48 @@
/*
* err - Incenp.org Notch Library: (v)(err|warn)(x) replacement
* Copyright (C) 2011 Damien Goutte-Gattat
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ICP20110203_ERR_H
#define ICP20110203_ERR_H
#include <stdarg.h>
#ifdef __cpluscplus
extern "C" {
#endif
void err(int, const char *, ...);
void errx(int, const char *, ...);
void verr(int, const char *, va_list);
void verrx(int, const char *, va_list);
void warn(const char *, ...);
void warnx(const char *, ...);
void vwarn(const char *, va_list);
void vwarnx(const char *, va_list);
#ifdef __cplusplus
}
#endif
#endif /* !ICP20110203_ERR_H */

31
lib/progname.c

@ -0,0 +1,31 @@
/*
* progname - Incenp.org Notch Library: (set/get)progname replacement
* Copyright (C) 2011 Damien Goutte-Gattat
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
static const char *progname;
void
setprogname(const char *name)
{
progname = name;
}
const char *
getprogname(void)
{
return progname;
}

16
m4/notch.m4

@ -0,0 +1,16 @@
dnl ICP_CHECK_NOTCH_FUNCS
dnl Check for various functions that may not be present
dnl everywhere, and for which we provide a replacement.
dnl
AC_DEFUN([ICP_CHECK_NOTCH_FUNCS],[
AC_CHECK_HEADERS([err.h], [], [AC_CONFIG_LINKS([err.h:lib/err.compat.h])])
AC_REPLACE_FUNCS([err])
AC_CHECK_DECLS([program_invocation_short_name], [],
[AC_CHECK_FUNCS([getprogname setprogname], [],
[AC_LIBOBJ([progname])])],
[#include <errno.h>
])
AC_CHECK_DECLS([P_tmpdir])
AH_BOTTOM([#include <compat.h>
])
])

7
src/Makefile.am

@ -0,0 +1,7 @@
bin_PROGRAMS = wait4
wait4_SOURCES = wait4.c
AM_CPPFLAGS = -I$(top_srcdir)/lib
AM_LDFLAGS = -L$(top_builddir)/lib
LDADD = -lwait4

93
src/wait4.c

@ -0,0 +1,93 @@
/*
* wait4 - Wait for an arbitrary process
* Copyright (C) 2013 Damien Goutte-Gattat
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
/* Help and informations about the program. */
static void
usage(int status)
{
puts("Usage: wait4 pid\n\
Wait until the specified process terminates.\n");
puts("Options:\n\
-h, --help Display this help message.\n\
-v, --version Display the version message.\n\
");
printf("Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
exit(status);
}
static void
info(void)
{
printf("\
wait4 %s\n\
Copyright (C) 2013 Damien Goutte-Gattat\n\
\n\
This program is released under the GNU General Public License.\n\
See the COPYING file or <http://www.gnu.org/licenses/gpl.html>.\n\
", VERSION);
exit(EXIT_SUCCESS);
}
/* Main function. */
int
main(int argc, char **argv)
{
int c;
struct option options[] = {
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'v' },
{ NULL, 0, NULL, 0 }
};
setprogname(argv[0]);
while ( (c = getopt_long(argc, argv, "hv", options, NULL)) != -1 ) {
switch ( c ) {
case 'h':
usage(EXIT_SUCCESS);
break;
case '?':
usage(EXIT_FAILURE);
break;
case 'v':
info();
break;
}
}
return EXIT_SUCCESS;
}
Loading…
Cancel
Save