4 * ROX-Filer, filer for the ROX desktop project
5 * By Thomas Leonard, <tal197@ecs.soton.ac.uk>.
8 /* support.c - (non-GUI) useful routines */
13 #include <sys/param.h>
20 /* Static prototypes */
23 /* Like g_strdup, but does realpath() too (if possible) */
24 char *pathdup(char *path
)
26 char real
[MAXPATHLEN
];
28 g_return_val_if_fail(path
!= NULL
, NULL
);
30 if (realpath(path
, real
))
31 return g_strdup(real
);
33 return g_strdup(path
);
36 /* Join the path to the leaf (adding a / between them) and
37 * return a pointer to a buffer with the result. Buffer is valid until
38 * the next call to make_path.
40 GString
*make_path(char *dir
, char *leaf
)
42 static GString
*buffer
= NULL
;
45 buffer
= g_string_new(NULL
);
47 g_return_val_if_fail(dir
!= NULL
, buffer
);
48 g_return_val_if_fail(leaf
!= NULL
, buffer
);
50 g_string_sprintf(buffer
, "%s%s%s",
52 dir
[0] == '/' && dir
[1] == '\0' ? "" : "/",
58 /* Return our complete host name */
61 static char *name
= NULL
;
67 g_return_val_if_fail(gethostname(buffer
, 4096) == 0,
71 name
= g_strdup(buffer
);
77 /* fork() and run a new program.
78 * Returns the new PID, or 0 on failure.
80 int spawn(char **argv
)
82 return spawn_full(argv
, NULL
, 0);
85 /* As spawn(), but cd to dir first (if dir is non-NULL) */
86 int spawn_full(char **argv
, char *dir
, SpawnFlags flags
)
93 return 0; /* Failure */
96 /* We are the child process */
99 fprintf(stderr
, "chdir() failed: %s\n",
101 execvp(argv
[0], argv
);
102 fprintf(stderr
, "execvp(%s, ...) failed: %s\n",
108 /* We are the parent */
112 void debug_free_string(void *data
)
114 g_print("Freeing string '%s'\n", (char *) data
);