我有一些简单的代码,但我收到一个警告:
-bash-3.2$ gcc -Wall print_process_environ.c -o p_p
print_process_environ.c: In function 'print_process_environ':
print_process_environ.c:24: warning: implicit declaration of function 'strlen'
print_process_environ.c:24: warning: incompatible implicit declaration of built-in function 'strlen'
以下是代码:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <strings.h>
void
print_process_environ(pid_t pid)
{
int fd;
char filename[24];
char environ[1024];
size_t length;
char *next_var;
snprintf(filename, sizeof(filename), "/proc/%d/environ", (int)pid);
printf("length of filename: %d\n", strlen(filename));
fd = open(filename, O_RDONLY);
......
的定义strlen()
是:
#include <string.h>
size_t strlen(const char *s);
如何摆脱这个警告。