summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 06b6077843..6695a85a1c 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -7433,3 +7433,27 @@ int sethostname_idempotent(const char *s) {
return 1;
}
+
+int ptsname_malloc(int fd, char **ret) {
+ size_t l = 100;
+
+ for (;;) {
+ char *c;
+
+ c = new(char, l);
+ if (!c)
+ return -ENOMEM;
+
+ if (ptsname_r(fd, c, l) == 0) {
+ *ret = c;
+ return 0;
+ }
+ if (errno != ERANGE) {
+ free(c);
+ return -errno;
+ }
+
+ free(c);
+ l *= 2;
+ }
+}