7 FILE *
open_file(
const char *filename,
const char*mode);
10 FILE *
open_file(
const char *filename,
const char*mode) {
11 FILE*file = fopen(filename, mode);
13 sm_error(
"Could not open file '%s': %s.\n", filename, strerror(errno));
20 if(!strcmp(filename,
"-" ))
return stdin;
21 if(!strcmp(filename,
"stdin"))
return stdin;
26 if(!strcmp(filename,
"-" ))
return stdout;
27 if(!strcmp(filename,
"stdout"))
return stdout;
28 if(!strcmp(filename,
"stderr"))
return stderr;
37 strcpy(dest, start+1);
42 if(!start) start = file;
else start += 1;
43 const char *end = strrchr(file,
'.');
44 if(!end || end<start) end = start + strlen(start);
46 strncpy(dest, start, (
size_t) (end-start));
47 dest[end-start] =
'\0';
53 const char *end = strrchr(file,
'.');
54 if(!end) end = file + strlen(file);
55 strncpy(dest, file, (
size_t) (end-file) );
56 dest[end-file] =
'\0';
62 size_t len = strlen(s) + 1;
63 char * t = (
char*) malloc(len);
void my_basename_no_suffix(const char *file, char *dest)
FILE * open_file_for_writing(const char *filename)
void my_basename(const char *file, char *dest)
FILE * open_file(const char *filename, const char *mode)
void my_no_suffix(const char *file, char *dest)
FILE * open_file_for_reading(const char *filename)
char * my_strdup(const char *s)
void sm_error(const char *msg,...)