Example #1
0
off_t lseek(int fd, off_t offset, int whence) {

	g_fs_seek_mode mode;
	if (whence == SEEK_SET) {
		mode = G_FS_SEEK_SET;
	} else if (whence == SEEK_CUR) {
		mode = G_FS_SEEK_CUR;
	} else if (whence == SEEK_END) {
		mode = G_FS_SEEK_END;
	}

	g_fs_seek_status status;
	int64_t result = g_seek_s(fd, offset, mode, &status);

	if (status == G_FS_SEEK_SUCCESSFUL) {
		return result;

	} else if (status == G_FS_SEEK_INVALID_FD) {
		errno = EBADF;

	} else {
		// TODO improve kernel error codes
		errno = EIO;

	}

	return -1;
}
Example #2
0
bool g_file_utils::read_bytes(g_fd fd, size_t offset, uint8_t* buffer, size_t len) {

	g_fs_seek_status s;
	g_seek_s(fd, offset, G_FS_SEEK_SET, &s);

	if (s != G_FS_SEEK_SUCCESSFUL) {
		return false;
	}

	return read_bytes(fd, buffer, len);
}