source: branches/3.2/mondo/src/lib/mr_sys.c @ 3498

Last change on this file since 3498 was 3498, checked in by Bruno Cornec, 4 years ago
  • Adds a mr_sys module for the mr_system function and a unit test
  • Property svn:eol-style set to native
File size: 875 bytes
Line 
1/*
2 * $Id$
3 *
4 * Code (c)2006-2016 Bruno Cornec <bruno@mondorescue.org>
5 *
6 *     Main file of mr_sys : a very small and simple
7 *     library for system management
8 *
9 * Provided under the GPLv2
10 */
11
12#ifndef _GNU_SOURCE
13#define _GNU_SOURCE
14#endif
15
16#include <stdio.h>
17#include <stdlib.h>
18
19#include "mr_err.h"
20#include "mr_msg.h"
21#include "mr_mem.h"
22
23/*
24 * Function that calls system in a sure way
25 */
26int mr_system_int(int line, const char *file, const char *fmt, ...) {
27
28    char *cmd = NULL;
29    int res = 0;
30    va_list args;
31
32    va_start(args,fmt);
33    /*
34    printf("Format : %s\n",fmt);
35    */
36    res = vasprintf(&cmd, fmt, args);
37    if (res == -1) {
38        mr_msg_int(1,line,file,"Unable to alloc memory in mr_asprintf\nExiting...");
39        mr_exit(-1,"Unable to alloc memory in mr_asprintf");
40    }
41    /*
42    printf("Command : %s\n",cmd);
43    */
44    res = system(cmd);
45    mr_free(cmd);
46    va_end(args);
47    return(res);
48}
Note: See TracBrowser for help on using the repository browser.