94c4527d97ff293029f99dbdca79e3cbf6956caa
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>
31 * Return allocated string with the session name found in the config
34 char *get_session_name(void)
36 char *path
, *session_name
= NULL
;
38 /* Get path to config file */
39 path
= config_get_default_path();
44 /* Get session name from config */
45 session_name
= config_read_session_name(path
);
46 if (session_name
== NULL
) {
50 DBG2("Config file path found: %s", path
);
51 DBG("Session name found: %s", session_name
);
62 * Prints a simple list of the options available to a command. This is intended
63 * to be easily parsed for bash completion.
65 void list_cmd_options(FILE *ofp
, struct poptOption
*options
)
68 struct poptOption
*option
= NULL
;
70 for (i
= 0; options
[i
].longName
!= NULL
; i
++) {
73 fprintf(ofp
, "--%s\n", option
->longName
);
75 if (isprint(option
->shortName
)) {
76 fprintf(ofp
, "-%c\n", option
->shortName
);
82 * fls: returns the position of the most significant bit.
83 * Returns 0 if no bit is set, else returns the position of the most
84 * significant bit (from 1 to 32 on 32-bit, from 1 to 64 on 64-bit).
86 #if defined(__i386) || defined(__x86_64)
88 unsigned int fls_u32(uint32_t x
)
96 : "=r" (r
) : "rm" (x
));
102 #if defined(__x86_64)
104 unsigned int fls_u64(uint64_t x
)
112 : "=r" (r
) : "rm" (x
));
119 static __attribute__((unused
))
120 unsigned int fls_u64(uint64_t x
)
127 if (!(x
& 0xFFFFFFFF00000000ULL
)) {
131 if (!(x
& 0xFFFF000000000000ULL
)) {
135 if (!(x
& 0xFF00000000000000ULL
)) {
139 if (!(x
& 0xF000000000000000ULL
)) {
143 if (!(x
& 0xC000000000000000ULL
)) {
147 if (!(x
& 0x8000000000000000ULL
)) {
156 static __attribute__((unused
))
157 unsigned int fls_u32(uint32_t x
)
163 if (!(x
& 0xFFFF0000U
)) {
167 if (!(x
& 0xFF000000U
)) {
171 if (!(x
& 0xF0000000U
)) {
175 if (!(x
& 0xC0000000U
)) {
179 if (!(x
& 0x80000000U
)) {
188 unsigned int fls_ulong(unsigned long x
)
190 #if (CAA_BITS_PER_LONG == 32)
198 * Return the minimum order for which x <= (1UL << order).
199 * Return -1 if x is 0.
201 int get_count_order_u32(uint32_t x
)
206 return fls_u32(x
- 1);
210 * Return the minimum order for which x <= (1UL << order).
211 * Return -1 if x is 0.
213 int get_count_order_u64(uint64_t x
)
218 return fls_u64(x
- 1);
222 * Return the minimum order for which x <= (1UL << order).
223 * Return -1 if x is 0.
225 int get_count_order_ulong(unsigned long x
)
230 return fls_ulong(x
- 1);
This page took 0.03599 seconds and 5 git commands to generate.