Skip to contentSkip to conversation

libxl: open code basename()

PATCH In review Christoph Egger 2 participants 3 messages Dec 15, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: open code basename()

Hi!

Attached patch open codes basename() with strrchr().
Fixes build on platforms like NetBSD where POSIX basename is available.

Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632

# HG changeset patch
# User cegger
# Date 1292410694 -3600
Support libxl on NetBSD

tools/libxl/xl_cmdimpl.c +1 -1
diff -r dcb46110d460 -r e8ce7e3e4b8c tools/libxl/xl_cmdimpl.c
@@ -5455,7 +5455,7 @@ int main_cpupoolcreate(int argc, char **
     if (!xlu_cfg_get_string (config, "name", &buf))
         name = strdup(buf);
     else
-        name = basename(filename);
+        name = strrchr(filename, '/') + 1;
     if (!libxl_name_to_cpupoolid(&ctx, name, &poolid)) {
         fprintf(stderr, "Pool name \"%s\" already exists\n", name);
         return -ERROR_FAIL;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 12 lines · Christoph Egger

Hi!

Attached patch open codes basename() with strrchr().
Fixes build on platforms like NetBSD where POSIX basename is available.

diff -r dcb46110d460 -r e8ce7e3e4b8c tools/libxl/xl_cmdimpl.c

tools/libxl/xl_cmdimpl.c int main_cpupoolcreate(int argc, char ** · line 5461

Quoted 8 lines
tools/libxl/xl_cmdimpl.c +1 -1
@@ -5455,7 +5455,7 @@ int main_cpupoolcreate(int argc, char **
     if (!xlu_cfg_get_string (config, "name", &buf))
         name = strdup(buf);
     else
-        name = basename(filename);
+        name = strrchr(filename, '/') + 1;
     if (!libxl_name_to_cpupoolid(&ctx, name, &poolid)) {
         fprintf(stderr, "Pool name \"%s\" already exists\n", name);
         return -ERROR_FAIL;

This is not correct.
strrchr returns NULL here if filename contains no '/'. This leads to name being 1.

Juergen

Signature · 5 lines
Juergen Gross                 Principal Developer Operating Systems
TSP ES&S SWE OS6                       Telephone: +49 (0) 89 3222 2967
Fujitsu Technology Solutions              e-mail: [email protected]
Domagkstr. 28                           Internet: ts.fujitsu.com
D-80807 Muenchen                 Company details: ts.fujitsu.com/imprint.html
#2 lore raw
Quoted 8 lines · On Wednesday 15 December 2010 13:23:54 Juergen Gross wrote:
Quoted 7 lines · Christoph Egger

Hi!

Attached patch open codes basename() with strrchr().
Fixes build on platforms like NetBSD where POSIX basename is available.

Quoted 16 lines

tools/libxl/xl_cmdimpl.c int main_cpupoolcreate(int argc, char ** · line 5461

Quoted 12 lines

diff -r dcb46110d460 -r e8ce7e3e4b8c tools/libxl/xl_cmdimpl.c

tools/libxl/xl_cmdimpl.c +1 -1
@@ -5455,7 +5455,7 @@ int main_cpupoolcreate(int argc, char **
     if (!xlu_cfg_get_string (config, "name", &buf))
         name = strdup(buf);
     else
-        name = basename(filename);
+        name = strrchr(filename, '/') + 1;
     if (!libxl_name_to_cpupoolid(&ctx, name, &poolid)) {
         fprintf(stderr, "Pool name \"%s\" already exists\n", name);
         return -ERROR_FAIL;

This is not correct.
strrchr returns NULL here if filename contains no '/'. This leads to name being 1.

Thanks for pointing this out. I haven't considered that case.

Christoph

Signature · 6 lines
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632