tools/interactive-wayland.c
static int
os_create_anonymous_file(off_t size)
{
    static const char template[] = "/weston-shared-XXXXXX";
    const char *path;
    char *name;
    int fd;
    int ret;

    path = getenv("XDG_RUNTIME_DIR");
    if (!path) {
        errno = ENOENT;
        return -1;
    }

    name = malloc(strlen(path) + sizeof(template));
    if (!name)
        return -1;

    strcpy(name, path);
    strcat(name, template);

    fd = create_tmpfile_cloexec(name);

    free(name);

    if (fd < 0)
        return -1;

    ret = os_resize_anonymous_file(fd, size);
    if (ret != 0) {
        close(fd);
        errno = ret;
        return -1;
    }

    return fd;
}
/*
 * Create a new, unique, anonymous file of the given size, and
 * return the file descriptor for it. The file descriptor is set
 * CLOEXEC. The file is immediately suitable for mmap()'ing
 * the given size at offset zero.
 *
 * The file should not have a permanent backing store like a disk,
 * but may have if XDG_RUNTIME_DIR is not properly implemented in OS.
 *
 * The file name is deleted from the file system.
 *
 * The file is suitable for buffer sharing between processes by
 * transmitting the file descriptor over Unix sockets using the
 * SCM_RIGHTS methods.
 *
 * If the C library implements posix_fallocate(), it is used to
 * guarantee that disk space is available for the file at the
 * given size. If disk space is insufficent, errno is set to ENOSPC.
 * If posix_fallocate() is not supported, program will fallback
 * to ftruncate() instead.
 */
Create a new, unique, anonymous file of the given size, and
return the file descriptor for it. The file descriptor is set
CLOEXEC. The file is immediately suitable for mmap()'ing
the given size at offset zero.

The file should not have a permanent backing store like a disk,
but may have if XDG_RUNTIME_DIR is not properly implemented in OS.

The file name is deleted from the file system.

The file is suitable for buffer sharing between processes by
transmitting the file descriptor over Unix sockets using the
SCM_RIGHTS methods.

If the C library implements posix_fallocate(), it is used to
guarantee that disk space is available for the file at the
given size. If disk space is insufficent, errno is set to ENOSPC.
If posix_fallocate() is not supported, program will fallback
to ftruncate() instead.
Create a new unique anonymous file of the given size and return the file descriptor for it . The file descriptor is set CLOEXEC . The file is immediately suitable for mmap () ' ing the given size at offset zero . The file should not have a permanent backing store like a disk but may have if XDG_RUNTIME_DIR is not properly implemented in OS . The file name is deleted from the file system . The file is suitable for buffer sharing between processes by transmitting the file descriptor over Unix sockets using the SCM_RIGHTS methods . If the C library implements posix_fallocate () it is used to guarantee that disk space is available for the file at the given size . If disk space is insufficent errno is set to ENOSPC . If posix_fallocate () is not supported program will fallback to ftruncate () instead .
static int
os_create_anonymous_file(off_t size)
{
    static const char template[] = "/weston-shared-XXXXXX";
    const char *path;
    char *name;
    int fd;
    int ret;
    path = getenv("XDG_RUNTIME_DIR");
    if (!path) {
        errno = ENOENT;
        return -1;
    }
    name = malloc(strlen(path) + sizeof(template));
    if (!name)
        return -1;
    strcpy(name, path);
    strcat(name, template);
    fd = create_tmpfile_cloexec(name);
    free(name);
    if (fd < 0)
        return -1;
    ret = os_resize_anonymous_file(fd, size);
    if (ret != 0) {
        close(fd);
        errno = ret;
        return -1;
    }
    return fd;
}
static int os_create_anonymous_file ( off_t size ) { static const char template [ ] = " " ; const char * path ; char * name ; int fd ; int ret ; path = getenv ( " " ) ; if ( ! path ) { errno = ENOENT ; return -1 ; } name = malloc ( strlen ( path ) + sizeof ( template ) ) ; if ( ! name ) return -1 ; strcpy ( name , path ) ; strcat ( name , template ) ; fd = create_tmpfile_cloexec ( name ) ; free ( name ) ; if ( fd < 0 ) return -1 ; ret = os_resize_anonymous_file ( fd , size ) ; if ( ret != 0 ) { close ( fd ) ; errno = ret ; return -1 ; } return fd ; }
Create a new, unique, anonymous file of the given size, and
 return the file descriptor for it.
Create a new unique anonymous file of the given size and return the file descriptor for it .