2 * Copyright (c) 2011 David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <common/error.h>
24 #include <common/utils.h>
32 * Return allocated string with the session name found in the config
35 char *get_session_name(void)
37 char *path
, *session_name
= NULL
;
39 /* Get path to config file */
40 path
= utils_get_home_dir();
45 /* Get session name from config */
46 session_name
= config_read_session_name(path
);
47 if (session_name
== NULL
) {
51 DBG2("Config file path found: %s", path
);
52 DBG("Session name found: %s", session_name
);
63 * Prints a simple list of the options available to a command. This is intended
64 * to be easily parsed for bash completion.
66 void list_cmd_options(FILE *ofp
, struct poptOption
*options
)
69 struct poptOption
*option
= NULL
;
71 for (i
= 0; options
[i
].longName
!= NULL
; i
++) {
74 fprintf(ofp
, "--%s\n", option
->longName
);
76 if (isprint(option
->shortName
)) {
77 fprintf(ofp
, "-%c\n", option
->shortName
);
83 * fls: returns the position of the most significant bit.
84 * Returns 0 if no bit is set, else returns the position of the most
85 * significant bit (from 1 to 32 on 32-bit, from 1 to 64 on 64-bit).
87 #if defined(__i386) || defined(__x86_64)
89 unsigned int fls_u32(uint32_t x
)
97 : "=r" (r
) : "rm" (x
));
103 #if defined(__x86_64)
105 unsigned int fls_u64(uint64_t x
)
113 : "=r" (r
) : "rm" (x
));
120 static __attribute__((unused
))
121 unsigned int fls_u64(uint64_t x
)
128 if (!(x
& 0xFFFFFFFF00000000ULL
)) {
132 if (!(x
& 0xFFFF000000000000ULL
)) {
136 if (!(x
& 0xFF00000000000000ULL
)) {
140 if (!(x
& 0xF000000000000000ULL
)) {
144 if (!(x
& 0xC000000000000000ULL
)) {
148 if (!(x
& 0x8000000000000000ULL
)) {
157 static __attribute__((unused
))
158 unsigned int fls_u32(uint32_t x
)
164 if (!(x
& 0xFFFF0000U
)) {
168 if (!(x
& 0xFF000000U
)) {
172 if (!(x
& 0xF0000000U
)) {
176 if (!(x
& 0xC0000000U
)) {
180 if (!(x
& 0x80000000U
)) {
189 unsigned int fls_ulong(unsigned long x
)
191 #if (CAA_BITS_PER_LONG == 32)
199 * Return the minimum order for which x <= (1UL << order).
200 * Return -1 if x is 0.
202 int get_count_order_u32(uint32_t x
)
207 return fls_u32(x
- 1);
211 * Return the minimum order for which x <= (1UL << order).
212 * Return -1 if x is 0.
214 int get_count_order_u64(uint64_t x
)
219 return fls_u64(x
- 1);
223 * Return the minimum order for which x <= (1UL << order).
224 * Return -1 if x is 0.
226 int get_count_order_ulong(unsigned long x
)
231 return fls_ulong(x
- 1);
This page took 0.042434 seconds and 5 git commands to generate.