Mercurial > code
comparison c/setprogname/setprogname.c @ 659:e40d082f9161
c: resurrection
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 15 Jul 2019 21:05:00 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
658:868663a44b5e | 659:e40d082f9161 |
---|---|
1 /* | |
2 * setprogname.c -- get or set the program name | |
3 * | |
4 * Copyright (c) 2011-2019 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #include <stdio.h> | |
20 #include <stdlib.h> | |
21 #include <string.h> | |
22 | |
23 /* | |
24 * Do not return NULL if the developer didn't call setprogname to | |
25 * prevent useless segfault. | |
26 */ | |
27 static const char *g_pname = ""; | |
28 | |
29 void | |
30 setprogname(const char *progname) | |
31 { | |
32 const char *p; | |
33 | |
34 /* Seek last / or \ on windows */ | |
35 if ((p = strrchr(progname, '/')) || (p = strrchr(progname, '\\'))) | |
36 g_pname = &p[1]; | |
37 else | |
38 g_pname = progname; | |
39 } | |
40 | |
41 const char * | |
42 getprogname(void) | |
43 { | |
44 return g_pname; | |
45 } |