Skip to content

Commit

Permalink
lib: posix: fs: add ftruncate support
Browse files Browse the repository at this point in the history
Add support for ftruncate in posix implementation

Signed-off-by: Karthikeyan Krishnasamy <[email protected]>
  • Loading branch information
karthi012 authored and cfriedt committed Apr 15, 2024
1 parent feae0a2 commit cd1ed1c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/zephyr/posix/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ ssize_t write(int file, const void *buffer, size_t count);
ssize_t read(int file, void *buffer, size_t count);
off_t lseek(int file, off_t offset, int whence);
int fsync(int fd);
int ftruncate(int fd, off_t length);

/* File System related operations */
int rename(const char *old, const char *newp);
Expand Down
15 changes: 15 additions & 0 deletions lib/posix/options/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,18 @@ int mkdir(const char *path, mode_t mode)

return 0;
}

/**
* @brief Truncate file to specified length.
*
*/
int ftruncate(int fd, off_t length)
{
struct posix_fs_desc *ptr = NULL;

ptr = z_get_fd_obj(fd, NULL, EBADF);
if (!ptr)
return -1;

return fs_truncate(&ptr->file, length);
}

0 comments on commit cd1ed1c

Please sign in to comment.