Skip to content

Commit 1cc26d5

Browse files
committed
preliminary user account name api design
1 parent 56e918e commit 1cc26d5

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

include/bu/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ set(bu_headers
4141
tc.h
4242
time.h
4343
units.h
44+
user.h
4445
uuid.h
4546
version.h
4647
vfont.h

include/bu/user.h

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/* U S E R . H
2+
* BRL-CAD
3+
*
4+
* Copyright (c) 2023 United States Government as represented by
5+
* the U.S. Army Research Laboratory.
6+
*
7+
* This library is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU Lesser General Public License
9+
* version 2.1 as published by the Free Software Foundation.
10+
*
11+
* This library is distributed in the hope that it will be useful, but
12+
* WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public
17+
* License along with this file; see the file named COPYING for more
18+
* information.
19+
*/
20+
21+
#include "common.h"
22+
23+
#include "bu/defines.h"
24+
25+
26+
/**
27+
* used to specify what name type is desired
28+
*/
29+
enum bu_name_type {
30+
BU_USER_ACCT, /**< user account name */
31+
BU_USER_REAL, /**< user real full name */
32+
BU_USER_AUTO /**< either account or real */
33+
};
34+
35+
36+
/**
37+
* Routine for obtaining user names
38+
*
39+
* Returns a given user's account name or real full name if available.
40+
* May return "unknown" if the name is not available. If 'name' is
41+
* empty, then the current user's name will be returned. If 'name' is
42+
* not empty, then it is used as a case-insensitive lookup string.
43+
*
44+
* If 'name' is NULL or size is 0, then dynamic memory will be
45+
* allocated with bu_malloc() and returned.
46+
*
47+
@code
48+
char name[128] = {0};
49+
(void)bu_user_name(BU_USER_AUTO, name, sizeof(name));
50+
51+
char *account = bu_user_name(BU_USER_ACCT, NULL, 0);
52+
bu_free(account);
53+
54+
char *name = bu_user_name(BU_USER_REAL, "username", 0);
55+
bu_free(name);
56+
@endcode
57+
*/
58+
BU_EXPORT char *
59+
bu_user_name(enum bu_user_type type, char *name, size_t size);
60+
61+
62+
/*
63+
* Local Variables:
64+
* mode: C
65+
* tab-width: 8
66+
* indent-tabs-mode: t
67+
* c-file-style: "stroustrup"
68+
* End:
69+
* ex: shiftwidth=4 tabstop=8
70+
*/

0 commit comments

Comments
 (0)