File: common.c

package info (click to toggle)
denemo 2.6.49-0.1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 66,916 kB
  • sloc: ansic: 94,587; lisp: 38,713; xml: 22,675; python: 1,930; sh: 1,239; makefile: 642; yacc: 288; sed: 93
file content (39 lines) | stat: -rw-r--r-- 850 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <glib.h>
#include <glib/gstdio.h>
#include "common.h"

void
g_test_print(const char *fmt, ...)
{
	va_list argp;
	va_start(argp, fmt);
#ifdef G_OS_WIN32
  vprintf(fmt, argp);
#else
  gchar* str = g_strconcat("\e[7m", fmt, "\e[27m", NULL);
	vprintf(str, argp);
  g_free(str);
#endif
	va_end(argp);
}

gboolean
delete_if_exists(gchar* path){
  if(g_file_test(path, G_FILE_TEST_EXISTS)){
    if(g_file_test(path, G_FILE_TEST_IS_DIR)){
      GError *error = NULL;
      GDir* dir = g_dir_open(path, 0, &error);
      gchar* filename = NULL;
      gchar* child = NULL;
      while (filename = (gchar *)g_dir_read_name(dir)){
        child = g_build_filename(path, filename, NULL);
        delete_if_exists(child);
        g_free(child);
      }
   }
   if(g_remove(path) < 0)
     g_warning("Could not remove %s", path);
  }
}