ftello

本文详细介绍了标准IO流中的位置操作函数,包括fseek/fseeko用于定位文件位置,ftell/ftello获取当前位置,rewind重置位置到文件开始,以及fgetpos/fsetpos保存和设置文件位置的方法。

ftell/ftello、fseek/fseeko、fsetpos/fgetpos、rewind

讲解了在标准IO流中position(位置)相关函数

#include <stdio.h>

int fseek(FILE *stream, long offset, int whence);
//Returns: current file position indicator(指示器) if OK, -1L on error
long ftell(FILE *stream);
//Returns:0 if OK, nonzero on error
void rewind(FILE *stream);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

fseekftelloffset都是long型的数。

  • 对于二进制文件:whence有三个取值SEEK_SETSEEK_CURSEEK_END
  • 对于文本文件:whence必须为SEEK_SET,offset只能为两个值,0—代表rewind到文件开头,或者使用ftell的返回值

rewindfunction sets the file position indicator for the stream pointed to by stream to the beginning of the file. It is equivalent to:(void) fseek(stream, 0L, SEEK_SET)

fseeko, ftello - seek to or report file position

相对于fseekftell,将offset的类型从long换成off_t

 #include <stdio.h>

int fseeko(FILE *stream, off_t offset, int whence);
//Returns: current file position indicator if OK, (off_t) -1 on error
off_t ftello(FILE *stream);
//Returns:0 if OK, nonzero on error
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

回顾3.6节关于off_t的讨论,off_t也可以大于32bits

fgetpos、fsetpos

The fgetpos() and fsetpos() functions are alternate interfaces equivalent to ftell() and fseek() (with whence set to SEEK_SET), setting and storing the current value of the file offset into or from the object referenced by pos.
On some non-UNIX systems, an fpos_t object may be a complex object and these routines may be the only way to portably reposition a text stream.

#include <stdio.h>
int fgetpos(FILE *stream, fpos_t *pos);
int fsetpos(FILE *stream, const fpos_t *pos);
  • 1
  • 2
  • 3

fgetposfile‘s position indicator的当前值存放到pos指向的object中去。
fsetpos相反

Using CC = aarch64-linux-gnu-gcc Using MQTT_PWD = /home/thn/at606_v1r3_server/mqtt/ [MQTT] CFLAGS: -I/home/thn/at606_v1r3_server/mqtt/head_mosq [MQTT] LDFLAGS: -L/home/thn/at606_v1r3_server/mqtt/lib /home/thn/at606_v1r3_server/mqtt/lib/libmosquitto.a Using OPENSSL_PWD = /home/thn/at606_v1r3_server/verify_area_key/ [OPENSSL] CFLAGS: -I/opt/include [OPENSSL] LDFLAGS: -L/home/thn/at606_v1r3_server/verify_area_key/lib -lcrypto -ljansson aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c cJSON_Parse.c -o cJSON_Parse.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c cJSON.c -o cJSON.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c link.c -o link.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c main.c -o main.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c mongoose.c -o mongoose.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c o4_recv_queue.c -o o4_recv_queue.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c save_config.c -o save_config.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c log.c -o log.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c init_logg.c -o init_logg.o init_logg.c: In function ‘rotate_log_file’: init_logg.c:125:46: warning: ‘%d’ directive output may be truncated writing 1 byte into a region of size between 0 and 1023 [-Wformat-truncation=] 125 | snprintf(old_file, sizeof(old_file), "%s.%d", current_log_path, MAX_BACKUP_INDEX); | ^~ init_logg.c:125:5: note: ‘snprintf’ output between 3 and 1026 bytes into a destination of size 1024 125 | snprintf(old_file, sizeof(old_file), "%s.%d", current_log_path, MAX_BACKUP_INDEX); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ init_logg.c:131:50: warning: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size between 0 and 1023 [-Wformat-truncation=] 131 | snprintf(old_file, sizeof(old_file), "%s.%d", current_log_path, i); | ^~ init_logg.c:131:9: note: ‘snprintf’ output between 3 and 1036 bytes into a destination of size 1024 131 | snprintf(old_file, sizeof(old_file), "%s.%d", current_log_path, i); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ init_logg.c:132:50: warning: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size between 0 and 1023 [-Wformat-truncation=] 132 | snprintf(new_file, sizeof(new_file), "%s.%d", current_log_path, i + 1); | ^~ init_logg.c:132:9: note: ‘snprintf’ output between 3 and 1036 bytes into a destination of size 1024 132 | snprintf(new_file, sizeof(new_file), "%s.%d", current_log_path, i + 1); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c parse_web_info.c -o parse_web_info.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c message_queue.c -o message_queue.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c http_server.c -o http_server.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c get_qmc5883_gps/at606drv.c -o get_qmc5883_gps/at606drv.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c get_qmc5883_gps/e902.c -o get_qmc5883_gps/e902.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c get_qmc5883_gps/lwgps.c -o get_qmc5883_gps/lwgps.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c get_qmc5883_gps/serial.c -o get_qmc5883_gps/serial.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c get_qmc5883_gps/i2c.c -o get_qmc5883_gps/i2c.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c bsp_gpio/gpio_led.c -o bsp_gpio/gpio_led.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c bsp_gpio/gpio_jamming.c -o bsp_gpio/gpio_jamming.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c verify_area_key/verify_key.c -o verify_area_key/verify_key.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c shared_memory/shared_memory.c -o shared_memory/shared_memory.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c miniz/miniZip.c -o miniz/miniZip.o miniz/miniZip.c: In function ‘extract_zip’: miniz/miniZip.c:91:39: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘mz_uint64’ {aka ‘long unsigned int’} [-Wformat=] 91 | printf("Extracted: %s (%llu bytes)\n", output_path, file_stat.m_uncomp_size); | ~~~^ ~~~~~~~~~~~~~~~~~~~~~~~ | | | | long long unsigned int mz_uint64 {aka long unsigned int} | %lu miniz/miniZip.c:59:58: warning: ‘snprintf’ output may be truncated before the last format character [-Wformat-truncation=] 59 | snprintf(output_path, sizeof(output_path), "%s/%s", output_dir, file_stat.m_filename); | ^ miniz/miniZip.c:59:9: note: ‘snprintf’ output 2 or more bytes (assuming 513) into a destination of size 512 59 | snprintf(output_path, sizeof(output_path), "%s/%s", output_dir, file_stat.m_filename); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c miniz/miniz_tdef.c -o miniz/miniz_tdef.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c miniz/miniz_tinfl.c -o miniz/miniz_tinfl.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c miniz/miniz_zip.c -o miniz/miniz_zip.o miniz/miniz_zip.c:189:9: note: #pragma message: Using fopen, ftello, fseeko, stat() etc. path for file I/O - this path may not support large files. 189 | #pragma message("Using fopen, ftello, fseeko, stat() etc. path for file I/O - this path may not support large files.") | ^~~~~~~ aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c miniz/miniz.c -o miniz/miniz.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c mqtt/mqtt.c -o mqtt/mqtt.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c mqtt/mqtt_json/mqtt_json.c -o mqtt/mqtt_json/mqtt_json.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c rx_5808/rtc6715/bsp_spi.c -o rx_5808/rtc6715/bsp_spi.o aarch64-linux-gnu-gcc -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include -c rx_5808/usb_recv_freq/usb_recv.c -o rx_5808/usb_recv_freq/usb_recv.o rx_5808/usb_recv_freq/usb_recv.c: In function ‘usb_recv_freq_video_data’: rx_5808/usb_recv_freq/usb_recv.c:48:20: warning: format ‘%x’ expects a matching ‘unsigned int’ argument [-Wformat=] 48 | printf("%02x "); | ~~~^ | | | unsigned int aarch64-linux-gnu-gcc -no-pie -g -I/home/thn/at606_v1r3_server/mqtt/head_mosq -I/opt/include cJSON_Parse.o cJSON.o link.o main.o mongoose.o o4_recv_queue.o save_config.o log.o init_logg.o parse_web_info.o message_queue.o http_server.o get_qmc5883_gps/at606drv.o get_qmc5883_gps/e902.o get_qmc5883_gps/lwgps.o get_qmc5883_gps/serial.o get_qmc5883_gps/i2c.o bsp_gpio/gpio_led.o bsp_gpio/gpio_jamming.o verify_area_key/verify_key.o shared_memory/shared_memory.o miniz/miniZip.o miniz/miniz_tdef.o miniz/miniz_tinfl.o miniz/miniz_zip.o miniz/miniz.o mqtt/mqtt.o mqtt/mqtt_json/mqtt_json.o rx_5808/rtc6715/bsp_spi.o rx_5808/usb_recv_freq/usb_recv.o -o app -lpthread -lrt -lm -L/home/thn/at606_v1r3_server/mqtt/lib /home/thn/at606_v1r3_server/mqtt/lib/libmosquitto.a -L/home/thn/at606_v1r3_server/verify_area_key/lib -lcrypto -ljansso那这些警告是什么意思
11-21
/** * @file * @brief Platform Configuration */ #ifndef _AP4_CONFIG_H_ #define _AP4_CONFIG_H_ /*---------------------------------------------------------------------- | defaults +---------------------------------------------------------------------*/ #define AP4_CONFIG_HAVE_STDIO_H #define AP4_CONFIG_HAVE_ASSERT_H #define AP4_CONFIG_HAVE_STRING_H #define AP4_CONFIG_HAVE_SNPRINTF #define AP4_CONFIG_HAVE_VSNPRINTF #define AP4_CONFIG_HAVE_INT64 /*---------------------------------------------------------------------- | byte order +---------------------------------------------------------------------*/ // define AP4_PLATFORM_BYTE_ORDER to one of these two choices #define AP4_PLATFORM_BYTE_ORDER_BIG_ENDIAN 0 #define AP4_PLATFORM_BYTE_ORDER_LITTLE_ENDIAN 1 #if !defined(AP4_PLATFORM_BYTE_ORDER) #if defined(__ppc__) #define AP4_PLATFORM_BYTE_ORDER AP4_PLATFORM_BYTE_ORDER_BIG_ENDIAN #elif defined(_MSC_VER) #if defined(_M_IX86) || defined(_M_X64) || defined(_M_ARM) || defined(_M_ARM64) #define AP4_PLATFORM_BYTE_ORDER AP4_PLATFORM_BYTE_ORDER_LITTLE_ENDIAN #endif #elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__) #define AP4_PLATFORM_BYTE_ORDER AP4_PLATFORM_BYTE_ORDER_LITTLE_ENDIAN #endif #endif /*---------------------------------------------------------------------- | standard C++ runtime +---------------------------------------------------------------------*/ #define APT_CONFIG_HAVE_NEW_H /*---------------------------------------------------------------------- | platform specifics +---------------------------------------------------------------------*/ /* Microsoft Platforms */ #if defined(_MSC_VER) #define AP4_CONFIG_INT64_TYPE __int64 #if (_MSC_VER >= 1400) && !defined(_WIN32_WCE) #define AP4_CONFIG_HAVE_FOPEN_S #define AP4_snprintf(s,c,f,...) _snprintf_s(s,c,_TRUNCATE,f,__VA_ARGS__) #define AP4_vsnprintf(s,c,f,a) _vsnprintf_s(s,c,_TRUNCATE,f,a) #define fileno _fileno #define AP4_fseek _fseeki64 #define AP4_ftell _ftelli64 #else #define AP4_snprintf _snprintf #define AP4_vsnprintf _vsnprintf #endif #if defined(_WIN32_WCE) #define AP4_fseek fseek #define AP4_ftell ftell #endif #if defined(_DEBUG) #define _CRTDBG_MAP_ALLOC #endif #endif /* Cygwin */ #if defined(__CYGWIN__) #define AP4_fseek fseek #define AP4_ftell ftell #endif /* Symbian */ #if defined(__SYMBIAN32__) #undef APT_CONFIG_HAVE_NEW_H #include "e32std.h" /** * Define the Platform byte order here * for Symbian. */ #define AP4_PLATFORM_BYTE_ORDER AP4_PLATFORM_BYTE_ORDER_LITTLE_ENDIAN #define AP4_fseek fseek #define AP4_ftell ftell #define explicit #endif /* Android */ #if defined(ANDROID) #if !defined(AP4_CONFIG_NO_RTTI) #define AP4_CONFIG_NO_RTTI #endif #if !defined(AP4_CONFIG_NO_EXCEPTIONS) #define AP4_CONFIG_NO_EXCEPTIONS #endif #endif /* Emscripten */ #ifdef __EMSCRIPTEN__ #define AP4_PLATFORM_BYTE_ORDER AP4_PLATFORM_BYTE_ORDER_LITTLE_ENDIAN #endif /*---------------------------------------------------------------------- | defaults +---------------------------------------------------------------------*/ #if !defined(AP4_CONFIG_INT64_TYPE) #define AP4_CONFIG_INT64_TYPE long long #endif #if !defined(AP4_fseek) #define AP4_fseek fseeko #endif #if !defined(AP4_ftell) #define AP4_ftell ftello #endif /* some compilers (ex: MSVC 8) deprecate those, so we rename them */ #if !defined(AP4_snprintf) #define AP4_snprintf snprintf #endif #if !defined(AP4_vsnprintf) #define AP4_vsnprintf vsnprintf #endif #endif // _AP4_CONFIG_H_ 详细注释上述代码
09-26
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值