Hi/2. Paul Eggert wrote: > On 01/13/2016 06:23 PM, KO Myung-Hun wrote: > >> + if (__libc_Back_ioFHToPath (fd, path, sizeof (path))) > > Don't parenthesize the argument of sizeof here. > >> + sprintf (result, "%s/%s", path, file); > > This won't work if PATH or FILE is longer than INT_MAX bytes. Please > just use memcpy or strcpy instead.
Updated. -- KO Myung-Hun Using Mozilla SeaMonkey 2.7.2 Under OS/2 Warp 4 for Korean with FixPak #15 In VirtualBox v4.1.32 on Intel Core i7-3615QM 2.30GHz with 8GB RAM Korean OS/2 User Community : http://www.ecomstation.co.kr
From a620fd3102eccf2afcba66fcb42c32d80c56c9cd Mon Sep 17 00:00:00 2001 From: KO Myung-Hun <komh@chollian.net> Date: Sat, 17 Jan 2015 18:54:05 +0900 Subject: [PATCH] openat_proc_name: port to OS/2 kLIBC OS/2 kLIBC provides a function to retrive a path from a fd. Use it instead of /proc/self/fd. * lib/openat-proc.c (openat_proc_name): Port to OS/2 kLIBC with __libc_Back_ioFHToPath(). --- lib/openat-proc.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lib/openat-proc.c b/lib/openat-proc.c index 15a8c79..1edc156 100644 --- a/lib/openat-proc.c +++ b/lib/openat-proc.c @@ -30,6 +30,10 @@ #include <string.h> #include <unistd.h> +#ifdef __KLIBC__ +# include <InnoTekLIBC/backend.h> +#endif + #include "intprops.h" #define PROC_SELF_FD_FORMAT "/proc/self/fd/%d/%s" @@ -56,6 +60,7 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file) return buf; } +#ifndef __KLIBC__ if (! proc_status) { /* Set PROC_STATUS to a positive value if /proc/self/fd is @@ -99,4 +104,30 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file) sprintf (result, PROC_SELF_FD_FORMAT, fd, file); return result; } +#else + /* OS/2 kLIBC provides a function to retrieve a path from a fd. Use it. */ + { + char path[_MAX_PATH]; + size_t bufsize; + char *result = buf; + + /* Get a path from a fd */ + if (__libc_Back_ioFHToPath (fd, path, sizeof path)) + return NULL; + + bufsize = strlen (path) + 1 + strlen (file) + 1; /* 1 for '/', 1 for null */ + if (OPENAT_BUFFER_SIZE < bufsize) + { + result = malloc (bufsize); + if (! result) + return NULL; + } + + strcpy (result, path); + strcat (result, "/"); + strcat (result, file); + + return result; + } +#endif } -- 2.7.0