[CONTACT]

[ABOUT]

[POLICY]

include include include include incl

Found at: ftp.icm.edu.pl:70/packages/netlib/crc/util.c

#define _POSIX_SOURCE
#include <stdio.h>
#include "stdlib.h"
#include "string.h"
#include "unistd.h"
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifdef __STDC__
extern int Error(char*,...);
#endif
#ifndef F_OK
#include <sys/file.h>	/* pre-POSIX */
#endif

/*
 * The author of this software is Eric Grosse.  Copyright (c) 1993 by AT&T.
 * Permission to use, copy, modify, and distribute this software for any
 * purpose without fee is hereby granted, provided that this entire notice
 * is included in all copies of any software which is or includes a copy
 * or modification of this software and in all copies of the supporting
 * documentation for such software.
 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTY.  IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY
 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
 * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
 */


#ifdef __STDC__
void
prCreate(char *path)
#else
prCreate(path)
	char *path;
#endif
{
	fprintf(stderr,"Create %s\n",path);
}
#ifdef __STDC__
void (*prCreate)(char*) = iprCreate;	/* user hook for different printing */
#else
nt (*prCreate)() = iprCreate;
#endif

#ifdef __STDC__
nt
Create(char *name, mode_t mode)
#else
	int Create(name,mode) char *name; int mode;
#endif
{
	/* like creat(), but makes intermediate directories and dies on error. */
	int fd;
	char *path, *e, *f;

	fd = creat(name,mode);
	if( fd<0 && errno==ENOENT ){
		path = (char*)malloc(strlen(name)+1);
		path || Error("malloc failed");
		strcpy(path,name);
		while(e = strrchr(path,'/')){
			*e = '\0';
			if(access(path,F_OK)==0) break;
		}
		if(!e) e = path-1;
		strcpy(path,name);	/* restore slashes */
		/* now e points to slash after existing directory */
		while(e = strchr(e+1,'/')){
			*e = '\0';
			prCreate(path);
			mkdir(path,0111|mode)==0 || Error("can't mkdir %s",path);
			*e = '/';
		}
		free(path);
		fd = creat(name,mode);
	}
	if(fd<0) Error("can't Create %s",name);
	return fd;
}



#ifdef __STDC__
#include <stdarg.h>

extern char *progname;		/* from main() */

nt
Error(char *fmt, ...)
{
	va_list ap;
	fprintf(stderr,"%s: ",progname);
	va_start(ap,fmt);
	if(vfprintf(stderr,fmt,ap)<0)
		fprintf(stderr,"<vfprintf error>");
	fputc('\n',stderr);
	va_end(ap);
	perror("");	/* may or may not be relevant */
	exit(1);
	/* NOTREACHED */
	return(0);	/* so caller can use  crunch() || Error("bad");  */
}

#else
nt Error(fmt) char* fmt;
{
	fputs(fmt,stderr);
	fputc('\n',stderr);
	perror("");
	exit(1);
	/* NOTREACHED */
	return(0);
}
#endif

.


AD:

NEW PAGES:

[ODDNUGGET]

[GOPHER]