/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
/* Create /proc/self/fd-related names for subfiles of open directories.
- Copyright (C) 2006, 2009-2010 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <fcntl.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include "dirname.h"
#include "intprops.h"
#include "same-inode.h"
-#include "xalloc.h"
/* The results of open() in this file are not used with fchdir,
and we do not leak fds to any single-threaded code that could use stdio,
/* Set BUF to the expansion of PROC_SELF_FD_FORMAT, using FD and FILE
respectively for %d and %s. If successful, return BUF if the
result fits in BUF, dynamically allocated memory otherwise. But
- return NULL if /proc is not reliable. */
+ return NULL if /proc is not reliable, either because the operating
+ system support is lacking or because memory is low. */
char *
openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file)
{
else
{
size_t bufsize = PROC_SELF_FD_NAME_SIZE_BOUND (strlen (file));
- char *result = (bufsize < OPENAT_BUFFER_SIZE ? buf : xmalloc (bufsize));
+ char *result = buf;
+ if (OPENAT_BUFFER_SIZE < bufsize)
+ {
+ result = malloc (bufsize);
+ if (! result)
+ return NULL;
+ }
sprintf (result, PROC_SELF_FD_FORMAT, fd, file);
return result;
}