1 /*
2  * Copyright 2016-2021 The Regents of the University of California
3  * All rights reserved.
4  *
5  * This file is part of Spoofer.
6  *
7  * Spoofer is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * Spoofer is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with Spoofer.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 /****************************************************************************
22    Author:      Ken Keys, CAIDA
23    Date:        $Date: 2021/04/28 17:39:09 $
24    Description: get application name
25 ****************************************************************************/
26 
27 /*
28  * Usage: at the beginning of main(), declare
29  *     AppInfo appInfo(argv[0]);
30  * then, anywhere in the program (within the lifetime of appInfo), get the
31  * application name by calling the static method
32  *     AppInfo::path()
33  */
34 
35 class AppInfo {
36     static char *appPath;
37     static char *appDir;
38 
39     AppInfo(const AppInfo&) NO_METHOD;
40     AppInfo operator=(const AppInfo&) NO_METHOD;
41 public:
42     AppInfo(const char *argv0);
~AppInfo()43     ~AppInfo() { if (appPath) free(appPath); appPath = nullptr; }
44 
45     static const char *path() ATR_PURE;
46     static const char *dir() ATR_PURE;
47 };
48