1 // Copyright 2016 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <launchpad/vmo.h> 6 #include <zircon/syscalls.h> 7 #include <lib/fdio/io.h> 8 9 #include <fcntl.h> 10 #include <string.h> 11 #include <unistd.h> 12 launchpad_vmo_from_file(const char * filename,zx_handle_t * out)13zx_status_t launchpad_vmo_from_file(const char* filename, zx_handle_t* out) { 14 int fd = open(filename, O_RDONLY); 15 if (fd < 0) 16 return ZX_ERR_IO; 17 zx_status_t status = fdio_get_vmo_clone(fd, out); 18 close(fd); 19 20 if (status == ZX_OK) { 21 if (strlen(filename) >= ZX_MAX_NAME_LEN) { 22 const char* p = strrchr(filename, '/'); 23 if (p != NULL) { 24 filename = p + 1; 25 } 26 } 27 28 zx_object_set_property(*out, ZX_PROP_NAME, filename, strlen(filename)); 29 } 30 31 return status; 32 } 33