Debian Codegraph @

src/examples/frobnicate.c

raw
1 /*
2 * Copyright (C) 2009 Red Hat, Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
18 *
19 * Author: David Zeuthen <[email protected]>
20 */
21
22 #include <glib.h>
23 #include <unistd.h>
24 #include <stdlib.h>
25 #include <errno.h>
26 #include <sys/types.h>
27
28 int
29 main (int argc, char *argv[])
30 {
31 gchar *args;
32 gchar **env;
33 guint n;
34 int ret;
35 #ifdef __GLIBC__
36 gchar *cwd = NULL;
37 #else
38 gchar cwd[PATH_MAX];
39 #endif
40
41 ret = 1;
42 args = NULL;
43 env = NULL;
44
45 #ifdef __GLIBC__
46 if ((cwd = get_current_dir_name ()) == NULL)
47 #else
48 if (getcwd (cwd, sizeof cwd) == NULL)
49 #endif
50 {
51 g_printerr ("Error getting cwd: %s\n", g_strerror (errno));
52 goto out;
53 }
54
55 args = g_strjoinv (" ", argv);
56
57 g_print ("In pk-example-frobnicate\n");
58 g_print ("uid: %d\n", getuid ());
59 g_print ("euid: %d\n", geteuid ());
60 g_print ("args: `%s'\n", args);
61 g_print ("cwd: %s\n", cwd);
62 g_print ("environment:\n");
63
64 env = g_listenv ();
65 for (n = 0; env[n] != NULL; n++)
66 {
67 g_print (" %s=%s\n", env[n], g_getenv (env[n]));
68 }
69
70 ret = 0;
71
72 out:
73
74 #ifdef __GLIBC__
75 free (cwd);
76 #endif
77 g_free (args);
78 g_strfreev (env);
79
80 return ret;
81 }