1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-12-18 15:26:23 -05:00

cleanup usage and wrapper

This commit is contained in:
Renaud 2013-04-30 17:24:46 +08:00 committed by Renaud Fivet
parent 128354e657
commit 68a79430e6
4 changed files with 42 additions and 28 deletions

29
usage.c
View File

@ -1,22 +1,27 @@
/* usage.c -- implements usage.h */
/* TODO: align exit return code */
#include "usage.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
static void report(const char* prefix, const char *err, va_list params)
{
char msg[4096];
vsnprintf(msg, sizeof(msg), err, params);
fprintf(stderr, "%s%s\n", prefix, msg);
static void report( const char *prefix, const char *err, va_list params) {
char msg[ 4096] ;
vsnprintf( msg, sizeof msg, err, params) ;
fprintf( stderr, "%s%s\n", prefix, msg) ;
}
void die(const char* err, ...)
{
va_list params;
void die( const char *err, ...) {
va_list params ;
va_start(params, err);
report("fatal: ", err, params);
va_end(params);
exit(128);
va_start( params, err) ;
report( "fatal: ", err, params) ;
va_end( params) ;
exit( 128) ;
}
/* end of usage.c */

View File

@ -1,6 +1,6 @@
#ifndef USAGE_H_
#define USAGE_H_
extern void die(const char* err, ...);
void die( const char *err, ...) ;
#endif /* USAGE_H_ */

View File

@ -1,22 +1,29 @@
/* wrapper.c -- implements wrapper.h */
#include "wrapper.h"
#include "usage.h"
#include <stdlib.h>
#include <unistd.h>
/* Function copyright: git */
int xmkstemp(char *template)
{
int fd;
void xmkstemp( char *template) {
int fd ;
fd = mkstemp(template);
if (fd < 0)
die("Unable to create temporary file");
return fd;
fd = mkstemp( template) ;
if( fd < 0)
die( "Unable to create temporary file") ;
close( fd) ;
}
void *xmalloc(size_t size)
{
void *ret = malloc(size);
if (!ret)
die("Out of memory");
return ret;
void *xmalloc( size_t size) {
void *ret = malloc( size) ;
if( !ret)
die( "Out of memory") ;
return ret ;
}
/* end of wrapper.c */

6
wrapper.h Normal file → Executable file
View File

@ -1,8 +1,10 @@
#ifndef WRAPPER_H_
#define WRAPPER_H_
extern int xmkstemp(char *template);
#include <stdlib.h>
extern void *xmalloc(size_t size);
void xmkstemp( char *template) ;
void *xmalloc( size_t size) ;
#endif /* WRAPPER_H_ */