ls.c:(.text+0x2dc): undefined reference to `S_ISSOCK'

OP (Company: no) #5066028
Rate this post
• ▲ useful
▼ not useful
1
if(S_ISDIR(statbuf.st_mode))
2
             printf("d");
3
        else if(S_ISCHR(statbuf.st_mode))
4
            printf("c");
5
        else if(S_ISBLK(statbuf.st_mode))
6
            printf("b");
7
        else if(S_ISREG(statbuf.st_mode))
8
            printf("-");
9
        else if(S_ISFIFO(statbuf.st_mode))
10
            printf("f");
11
        else if(S_ISLNK(statbuf.st_mode))
12
            printf("l");
13
        else if(S_ISSOCK(statbuf.st_mode))
14
            printf("s");
I read the manual here 
https://www.gnu.org/software/libc/manual/html_node/Testing-File-Type.html
This code after compilation produces this error, if I comment on the 
line with this error, then the error disappears
Guest #5069675
Rate this post
• ▲ useful
▼ not useful
Kirkina A. wrote:
>> Compile with
>>
1
>> -D_XOPEN_SOURCE=500
2
>>
>>
>> man 2 stat
>>
>> should have shown you that.
>
> man 2 stat did not show it.

Seems this has been moved to a separate man page lately. On my linux 
system, this is mentioned in man 2 stat, but the latest version of the 
linux man page project 
(http://man7.org/linux/man-pages/man2/stat.2.html) just says:
1
st_mode
2
              This field contains the file type and mode.  See inode(7) for
3
              further information.

and the inode man page says:
1
The definitions of most of the above file type test macros are
2
provided if any of the following feature test macros is defined:
3
_BSD_SOURCE (in glibc 2.19 and earlier), _SVID_SOURCE (in glibc 2.19
4
and earlier), or _DEFAULT_SOURCE (in glibc 2.20 and later).  In
5
addition, definitions of all of the above macros except S_IFSOCK and
6
S_ISSOCK() are provided if _XOPEN_SOURCE is defined.  The definition
7
of S_IFSOCK can also be exposed by defining _XOPEN_SOURCE with a
8
value of 500 or greater.

Reply

A question of your own? This thread is over 9 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.