various fixes for vc++. I'll add the Visual Studio projects later
[profile/ivi/ecore.git] / src / lib / ecore / ecore_app.c
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4
5 #ifdef HAVE_CONFIG_H
6 # include <config.h>
7 #endif
8
9 #include <stdlib.h>
10
11 #ifndef _MSC_VER
12 # include <unistd.h>
13 #endif
14
15 #ifdef HAVE_EVIL
16 # include <Evil.h>
17 #endif
18
19 #include "Ecore.h"
20 #include "ecore_private.h"
21
22 static int app_argc = 0;
23 static char **app_argv = NULL;
24
25 /**
26  * Set up the programs command-line arguments.
27  * @param argc The same as passed as argc to the programs main() function
28  * @param argv The same as passed as argv to the programs main() function
29  *
30  * A call to this function will store the programs command-line arguments
31  * for later use by ecore_app_restart() or ecore_app_args_get().
32  */
33 EAPI void
34 ecore_app_args_set(int argc, const char **argv)
35 {
36    if ((argc < 1) ||
37        (!argv)) return;
38    app_argc = argc;
39    app_argv = (char **)argv;
40 }
41
42 /**
43  * Return the programs stored command-line arguments.
44  * @param argc A pointer to the return value to hold argc
45  * @param argv A pointer to the return value to hold argv
46  *
47  * When called, this funciton returns the arguments for the program stored by
48  * ecore_app_args_set(). The integer pointed to by @p argc will be filled, if
49  * the pointer is not NULL, and the string array pointer @p argv will be filled
50  * also if the pointer is not NULL. The values they are filled with will be the
51  * same set by ecore_app_args_set().
52  */
53 EAPI void
54 ecore_app_args_get(int *argc, char ***argv)
55 {
56    if (argc) *argc = app_argc;
57    if (argv) *argv = app_argv;
58 }
59
60 /**
61  * Restart the program executable with the command-line arguments stored.
62  *
63  * This function will restart & re-execute this program in place of itself
64  * using the command-line arguments stored by ecore_app_args_set(). This is
65  * an easy way for a program to restart itself for cleanup purposes,
66  * configuration reasons or in the event of a crash.
67  */
68 EAPI void
69 ecore_app_restart(void)
70 {
71    char *args[4096];
72    int i;
73
74    if ((app_argc < 1) || (!app_argv)) return;
75    if (app_argc >= 4096) return;
76    for (i = 0; i < app_argc; i++) args[i] = app_argv[i];
77    args[i] = NULL;
78    execvp(app_argv[0], args);
79 }