News for hackers. Stuff that matters.
Re:Linus vs C++, again by tptacek on Thursday June 10, 2010 @05:04PM (#1421677)
That's userland code. In the kernel, write(2) very quickly finds the open file based on the fd and passes the call off to extremely explicit code that handles the write().

Stripping off ambiguity is almost the write syscall handler's only job.

It's worth mentioning here that not only is the convenience vs. explicitness tradeoff different in application code than in bare-metal systems programming code, but that that specific example of convenient app-level API is also an infamous Unix failure. In reality, app code cannot safely assume that an fd is just an abstract bucket you can read, write, close, and seek in.

Re:Linus vs C++, again by ramidarigaz on Thursday June 10, 2010 @06:50PM (#1422042)
I've been meaning to ask this for a very long time: What does the (2) mean? I see (n) in lots of descriptions of calls, but I've never found out what it means.
Re:Linus vs C++, again by eru on Thursday June 10, 2010 @07:03PM (#1422085)
It refers to sections of the man pages. They are organized like this:

1. General Commands

2. System Calls

3. Subroutines

4. Special Files

5. File Formats

6. Games

7. Macros and Conventions

8. Maintenence Commands

Re:Linus vs C++, again by ramidarigaz on Friday June 11, 2010 @01:40PM (#1424065)
Exactly what I wanted to know. Thanks.
Re:Linus vs C++, again by cycojesus on Saturday June 12, 2010 @04:00AM (#1425728)
and it's used like this: man 2 write
Re:Linus vs C++, again by tptacek on Thursday June 10, 2010 @07:25PM (#1422138)
You got a lot of good answers here, but just so you know: you really only have to remember that open(2) is a syscall and fopen(3) is a library call. That's the important distinction.
Re:Linus vs C++, again by jbarham on Thursday June 10, 2010 @07:04PM (#1422091)
The Unix manual is divided into sections (http://en.wikipedia.org/wiki/Man_page#Manual_sections). Section 2 is for system calls. Specifying the section number allows you to disambiguate which section of the manual you want to look in if a man page exists in multiple sections (e.g., "man 1 write" vs. "man 2 write").
Re:Linus vs C++, again by stonemetal on Thursday June 10, 2010 @07:06PM (#1422096)
It is where it lives in man. man write returns write(1) an application that sends a message to another user. man 2 write returns write(2) the system call mentioned above(or at least it does on Ubuntu).
Re:Linus vs C++, again by gxti on Thursday June 10, 2010 @07:04PM (#1422090)
It's the "man" section. According to "man man", 2 is the section for system calls. Often you'll have manpages for the same name under different sections, for example sync(1) is a command while sync(2) a system call (which, unsurprisingly, the sync command uses).
Re:Linus vs C++, again by bretthoerner on Thursday June 10, 2010 @07:05PM (#1422093)
It's the man page section number. I believe this dates back to when the man(uals) were actually printed out. You'd go to section 2 to find X to disambiguate from a different Y.

http://www.december.com/unix/ref/mansec.html

Re:Linus vs C++, again by eru on Thursday June 10, 2010 @07:18PM (#1422125)
And the disambiguation is still useful.