Project

General

Profile

Download (1.82 KB) Statistics
| Branch: | Tag: | Revision:
7e8045d8 David Sorber
/**
* Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl
*
*/
#ifndef PUTILS_H
#define PUTILS_H
#include <stdio.h>
#include <sys/stat.h>
FILE* do_creat(const char *fullname);
FILE* do_open_for_read(const char *fullname);
void do_fclose(FILE *f);
void do_write(FILE *f, const char *bytes, size_t size);
size_t do_read(FILE *f, char *bytes, size_t size);

int do_mkdir(const char *fullname);
// Effect: Create a directory (and its parents). If the directory exists, don't complain.

int do_mkfifo(const char *fullname, mode_t mode);
// Effect: Create a fifo.

int do_link(const char *linkto, const char *fullname);
int do_symlink(const char *contents, const char *fullname);
// Effect: If the symlink exists, return non-zero.

void do_unlink(const char *fullname);
void do_rmdir(const char *fullname);
char *pathcat(const char *a, const char *b);

// The main() compilation unit must provide this.
void help(int exitcode);
size_t parse_number_or_help(const char *numstring);


//Forward declaration of struct FTW as giving compilation error.
struct FTW;
int delete_subtree(const char *path, const struct stat *st, int typeflag, struct FTW *ftw);
void delete_dir_recursively(const char *path);

/************************************************************************/

void
maybe_error(int r, const char *fun, const char *fname, const char *srcfile, int line);

#define MAYBE_ERROR(fun, fname, args...) maybe_error(fun(fname, ##args), #fun, fname, __FILE__, __LINE__)


void
maybe_error2(int r, const char *fun, const char *fname, const char *fname2, const char *srcfile, int line);

#define MAYBE_ERROR2(fun, fname1, fname2, args...) maybe_error2(fun(fname1, fname2, ##args), #fun, fname1, fname2, __FILE__, __LINE__)

#endif