diff options
Diffstat (limited to 'hurd/porting/guidelines.mdwn')
-rw-r--r-- | hurd/porting/guidelines.mdwn | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/hurd/porting/guidelines.mdwn b/hurd/porting/guidelines.mdwn index 50d73601..624f7fd5 100644 --- a/hurd/porting/guidelines.mdwn +++ b/hurd/porting/guidelines.mdwn @@ -132,6 +132,8 @@ If you get Bad File Descriptor error when trying to read from a file (or accessi <http://pubs.opengroup.org/onlinepubs/009695399/basedefs/limits.h.html> +Also see <https://eklitzke.org/path-max-is-tricky> and <https://insanecoding.blogspot.com/2007/11/pathmax-simply-isnt.html> + Every unconditionalized use of `PATH_MAX`, `MAX_PATH` or `MAXPATHLEN` is a POSIX incompatibility. If there is no upper limit on the length of a path (as its the case for GNU), this symbol is not defined in any header file. Instead, you need to either use a different implementation that does not rely on the length of a string or use `sysconf()` to query the length at runtime. If `sysconf()` returns -1, you have to use `realloc()` to allocate the needed memory dynamically. Usually it is thus simpler to just use dynamic allocation. Sometimes the amount is actually known. Else, a geometrically growing loop can be used: for instance, see [Pulseaudio patch](http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=patch-pulse;att=1;bug=522100). Note that in some cases there are GNU extensions that just work fine: when the `__GLIBC__` macro is defined, `getcwd()` calls can be just replaced by `get_current_dir_name()` calls. Note: constants such as `_POSIX_PATH_MAX` are only the minimum required value @@ -140,10 +142,10 @@ for a potential corresponding `PATH_MAX` macro. They are not a replacement for Note 2: Yes, some POSIX functions such as `realpath()` actually assume that `PATH_MAX` is defined. This is a bug of the POSIX standard, which got fixed in -POSIX 2001, in which one can simply pass `NULL` to get a dynamically +POSIX 2008, in which one can simply pass `NULL` to get a dynamically allocated buffer. One can thus use: - #if _POSIX_VERSION >= 200112 || defined(__GLIBC__) + #if _POSIX_VERSION >= 200809 || defined(__GLIBC__) char *path = realpath(orig, NULL); #else char path[PATH_MATH]; @@ -158,7 +160,7 @@ Same rationale as `PATH_MAX`. There is no limit on the number of arguments. Same rationale as `PATH_MAX`. There is no limit on the number of iovec items. -## <a name="MAXHOSTNAMELEN_tt_"> `MAXHOSTNAMELEN` </a> +## <a name="MAXHOSTNAMELEN_tt_"> `MAXHOSTNAMELEN`, `HOST_NAME_MAX` </a> Same as `PATH_MAX`. When you find a `gethostname()` function, which acts on a static buffer, you can replace it with Neal's [xgethostname function](http://walfield.org/pub/people/neal/xgethostname/) which returns the hostname as a dynamic buffer. For example: @@ -198,7 +200,7 @@ kernel. This should be replaced by `#if defined(__MACH__) && defined(__APPLE__)` Some applications unconditionally use Darwin-specific functions coming from `mach/clock.h` to get the clock. This is unnecessarily unportable, -`clock_gettime` can simply be used instead, and the `#ifdef __MACH__` guard for the `mach/clock.h` +`clock` or `clock_gettime` can simply be used instead, and the `#ifdef __MACH__` guard for the `mach/clock.h` inclusion be fixed as explained above. ## <a name="GNU_specific_define_tt_"> </a> GNU specific `#define` |