diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-03-01 21:55:01 +0800 | 
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-03-01 21:55:01 +0800 | 
| commit | d1a73d00165c84fcf3d0308a23d8360589842fd9 (patch) | |
| tree | f1a40c28a02262829b36a991504d9874c986c64b | |
| parent | 36e0449df425341c4ae023d96812b1687e4350dc (diff) | |
| download | crupest-d1a73d00165c84fcf3d0308a23d8360589842fd9.tar.gz crupest-d1a73d00165c84fcf3d0308a23d8360589842fd9.tar.bz2 crupest-d1a73d00165c84fcf3d0308a23d8360589842fd9.zip | |
feat(hurd): add *_max sample fix.
| -rw-r--r-- | .editorconfig | 3 | ||||
| -rw-r--r-- | hurd/path_max.c | 63 | 
2 files changed, 66 insertions, 0 deletions
| diff --git a/.editorconfig b/.editorconfig index d1a54da..e0b1274 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,6 +11,9 @@ trim_trailing_whitespace = true  indent_style = tab  tab_width = 8 +[*.{c,cpp,h}] +indent_size = 2 +  [*.{yaml,yml}]  indent_size = 2 diff --git a/hurd/path_max.c b/hurd/path_max.c new file mode 100644 index 0000000..eee777c --- /dev/null +++ b/hurd/path_max.c @@ -0,0 +1,63 @@ +#include <errno.h> +#include <stdlib.h> +#include <unistd.h> + +static inline char *xreadlink(const char *restrict path) { +  char *buffer; +  size_t allocated = 128; +  ssize_t len; + +  while (1) { +    buffer = (char *)malloc(allocated); +    if (!buffer) { +      return NULL; +    } +    len = readlink(path, buffer, allocated); +    if (len < (ssize_t)allocated) { +      return buffer; +    } +    free(buffer); +    if (len >= (ssize_t)allocated) { +      allocated *= 2; +      continue; +    } +    return NULL; +  } +} + +static inline char *xgethostname() { +  long max_host_name; +  char *buffer; + +  max_host_name = sysconf(_SC_HOST_NAME_MAX); +  buffer = malloc(max_host_name + 1); + +  if (gethostname(buffer, max_host_name + 1)) { +    free(buffer); +    return NULL; +  } + +  buffer[max_host_name] = '\0'; +  return buffer; +} + +static inline char *xgetcwd() { +  char *buffer; +  size_t allocated = 128; + +  while (1) { +    buffer = (char *)malloc(allocated); +    if (!buffer) { +      return NULL; +    } +    getcwd(buffer, allocated); +    if (buffer) +      return buffer; +    free(buffer); +    if (errno == ERANGE) { +      allocated *= 2; +      continue; +    } +    return NULL; +  } +} | 
