Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ssize_t and off_t definitions from sys/types.h #37712

Merged
merged 2 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions include/fs/fs.h
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
/*
* Copyright (c) 2016 Intel Corporation.
* Copyright (c) 2020 Nordic Semiconductor ASA
* Copyright (c) 2020-2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_INCLUDE_FS_FS_H_
#define ZEPHYR_INCLUDE_FS_FS_H_

#ifdef CONFIG_ARCH_POSIX
#ifndef __ssize_t_defined
typedef __SIZE_TYPE__ ssize_t;
#define __ssize_t_defined
#endif

#ifndef __off_t_defined
#ifndef __USE_FILE_OFFSET64
typedef long int off_t;
#else
typedef long long int off_t;
#endif
#define __off_t_defined
#endif

#else
#include <sys/types.h>
#endif

#include <sys/dlist.h>
#include <fs/fs_interface.h>
Expand Down
18 changes: 14 additions & 4 deletions samples/subsys/fs/littlefs/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
#include <fs/littlefs.h>
#include <storage/flash_map.h>

/*
* FIXME: The Zephyr always overrides uintptr_t as long int, which causes type size mismatch with
* 32bit tools that may define PRIuPTR as "u".
* See: include/toolchain/zephyr_stdint.h.
* The UINTPTR_T_CAST should be replaced with cast to uintptr_t when this thing gets fixed.
*/
#undef PRIuPTR
#define PRIuPTR "lu"
#define UINTPTR_T_CAST(t) ((unsigned long)(t))

/* Matches LFS_NAME_MAX */
#define MAX_PATH_LEN 255

Expand Down Expand Up @@ -73,8 +83,8 @@ void main(void)
!(FSTAB_ENTRY_DT_MOUNT_FLAGS(PARTITION_NODE) & FS_MOUNT_FLAG_AUTOMOUNT)
rc = fs_mount(mp);
if (rc < 0) {
printk("FAIL: mount id %u at %s: %d\n",
(unsigned int)mp->storage_dev, mp->mnt_point,
printk("FAIL: mount id %" PRIuPTR " at %s: %d\n",
UINTPTR_T_CAST(mp->storage_dev), mp->mnt_point,
rc);
return;
}
Expand All @@ -100,7 +110,7 @@ void main(void)
rc = fs_stat(fname, &dirent);
printk("%s stat: %d\n", fname, rc);
if (rc >= 0) {
printk("\tfn '%s' siz %u\n", dirent.name, dirent.size);
printk("\tfn '%s' size %zu\n", dirent.name, dirent.size);
}

struct fs_file_t file;
Expand Down Expand Up @@ -149,7 +159,7 @@ void main(void)
printk("End of files\n");
break;
}
printk(" %c %u %s\n",
printk(" %c %zu %s\n",
(ent.type == FS_DIR_ENTRY_FILE) ? 'F' : 'D',
ent.size,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"%zu" instead

ent.name);
Expand Down