/* * $Id$ * * Code (c)2006-2016 Bruno Cornec * * Main file of mr_sys : a very small and simple * library for system management * * Provided under the GPLv2 */ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include #include #include "mr_err.h" #include "mr_msg.h" #include "mr_mem.h" /* * Function that calls system in a sure way */ int mr_system_int(int line, const char *file, const char *fmt, ...) { char *cmd = NULL; int res = 0; va_list args; va_start(args,fmt); /* printf("Format : %s\n",fmt); */ res = vasprintf(&cmd, fmt, args); if (res == -1) { mr_msg_int(1,line,file,"Unable to alloc memory in mr_asprintf\nExiting..."); mr_exit(-1,"Unable to alloc memory in mr_asprintf"); } /* printf("Command : %s\n",cmd); */ res = system(cmd); mr_free(cmd); va_end(args); return(res); }