CCExceptions development

Posted on Mon Mar 13, 2017

Maybe (and I say: maybe) things are getting into shape. Here is a program that prints the entries of a directory:

#include "ccexceptions.h"

int
main (int argc, const char *const argv[])
{
  static const char *           progname = "listdir";
  cce_location_t                L[1];
  cce_handler_dirstream_t       dirstream_H[1];
  const char *                  pathname;

  pathname = (2 == argc)? argv[1] : "./";

  if (cce_location(L)) {
    cce_run_error_handlers(L);
    fprintf(stderr, "%s: error: %s\n", progname,
            cce_condition_static_message(cce_condition(L)));
    cce_condition_free(cce_condition(L));
    exit(EXIT_FAILURE);
  } else {
    DIR *               dirstream;
    struct dirent *     direntry;

    dirstream = cce_sys_opendir(L, pathname);
    cce_cleanup_handler_dirstream_init(L, dirstream_H, dirstream);
    while ((direntry = cce_sys_readdir(L, dirstream))) {
      printf("%s\n", direntry->d_name);
      fflush(stdout);
    }
    cce_run_cleanup_handlers(L);
    exit(EXIT_SUCCESS);
  }
}

I’m adding wrappers for the most common posix functions, along with some gnu C Library and Linux specific functions.