如何在没有警告的情况下在C99中使用ftruncate [英] How to use ftruncate in c99 without warning

查看:169
本文介绍了如何在没有警告的情况下在C99中使用ftruncate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在代码中使用ftruncate函数。我必须使用选项std = c99进行编译。我得到警告:

I want to use ftruncate function in my code. I have to compile with option std=c99. I get warning:

In function ‘test’:
warning: implicit declaration of function ‘ftruncate’ [-Wimplicit-function-declaration]

我想在互联网上找到可以解决此问题的任何解决方案,但我

I tied to find on the Internet any solution which can solve this problem but I don't succeeded in.

我使用ftrucnate是因为我想在锁定(锁定)后清除打开的文件的内容。

I use ftrucnate because I want to clear content of an opened file after I get lock (flock).

推荐答案

由于 ftruncate()不是标准的C函数,因此您要求执行标准,则需要定义适当的功能测试宏(请参见 feature_test_macros(7))。

Since ftruncate() isn't a standard C function, and you've asked for standards enforcement, you need to define the appropriate feature test macros (see feature_test_macros(7)).

ftruncate(2)联机帮助页:


   ftruncate():
       _BSD_SOURCE || _XOPEN_SOURCE >= 500 ||
       _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
       || /* Since glibc 2.3.5: */ _POSIX_C_SOURCE >= 200112L


换句话说,要公开 ftruncate()函数,您必须定义以下宏之一,例如:

In other words, to expose the ftruncate() function you must define one of these macros, for example:

gcc -c -std=c99 -D_XOPEN_SOURCE=500 myfile.c

这篇关于如何在没有警告的情况下在C99中使用ftruncate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆