Questions tagged [unistd.h]

unistd.h is a C/C++ header files contains needed to provide access to the POSIX operating systems

Links:

https://en.wikipedia.org/wiki/Unistd.h

https://pubs.opengroup.org/onlinepubs/009695399/basedefs/unistd.h.html

175 questions
5
votes
1 answer

Clock, rdtsc and CLOCKS_PER_SEC

I am trying to implement my own version of clock() using asm and rdtsc. However I am quite unsure about its return value. Is it cycles? Oder is it micro seconds? I am also confused about CLOCKS_PER_SEC. How can this be constant? Is there any kind…
今天春天
  • 941
  • 1
  • 13
  • 27
5
votes
0 answers

unistd.h file not found, clang++ and OS X

I'm currently struggling with clang++, and after looking on the web for a long time I decided asking my question. I'm on OS X and using clang++ via Emacs (it's used by flycheck to highlight errors, among other things). I have a very simple file that…
Maxime Briand
  • 51
  • 1
  • 5
5
votes
1 answer

pread and pwrite not defined?

I am trying to use pread and pwrite so that I can lseek to the beginning of the file and start reading or writing in one atomic operation. Both of these functions will do that for me however, the issue I am having is that the compiler is giving me…
tpar44
  • 1,431
  • 4
  • 22
  • 35
4
votes
1 answer

How am I able to use read() and write() without including "unistd.h"?

I have used syscalls read() and write() in my program WITHOUT including "unistd.h" header file in the program. But still the program works and gives expected results. After running the program, i thought i will read the man page for read() and…
sps
  • 2,720
  • 2
  • 19
  • 38
3
votes
2 answers

I have a trouble with looking into the read() function code defined in

I am now trying to understand how read(2) function works by looking into the actual code implementation and first, I try to see how it is defined in #include header file. In that file, I found this : ssize_t read(int, void *, size_t)…
H.Potter
  • 137
  • 2
  • 9
3
votes
2 answers

atomic append on a file descriptor, but at what offset?

in unistd.h using open() with the O_APPEND flag gives atomic writes always to the end of the file... this is great and all, but what if i need to know the offset at which it atomically appended to the file...? i realize O_APPEND is often used for…
Michael Xu
  • 557
  • 1
  • 5
  • 14
3
votes
2 answers

C and write() function - File is being written in hexadecimal and written int value is not correct

I am trying to write into a file using the write() function (included in ). The program is simple: when running the executable, I type a message and then, the message and my user id (Linux UID) are saved into the file. $ ./notetaker…
Stanley Sathler
  • 368
  • 2
  • 12
3
votes
1 answer

Unistd read() maximum size

In the following snippet, no matter how long of an input I put in (EDIT: I'm copy and pasting in a random string), say a string with 9998 characters, read() stops when i = 4095. It states it read in an EOF character, but my string does not have an…
Poptart
  • 331
  • 4
  • 16
3
votes
2 answers

Open file in linux. I don't want to create a write-protected file

I have a problem when I create a file in Linux it makes my file write-protected and I don't know why it does that. void fileOperation::openFileWrite(char x, off_t s) { int fd; char c[2] = {x}; fd = open("/home/stud/txtFile", O_CREAT |…
Loc Dai Le
  • 1,661
  • 4
  • 35
  • 70
3
votes
2 answers

Standard POSIX read shadowed by a read method with different signature

I have a C++ File class with read function, that is supposed to read whole contents of a file (just like Python does) into a buffer. However, when I tried to call read function from unistd.h, I get: file.cpp:21: error: no matching function for call…
gruszczy
  • 40,948
  • 31
  • 128
  • 181
2
votes
2 answers

C Argv check which argv path came from what input

If i input paths with wildcards as command line parameters, like: testprogramm a* b* and the directory contains the following content: aa ab ba bb my argv string will contain: {"testprogramm","aa","ab","ba","bb"} However, i want to differentiate…
Bogomips
  • 33
  • 4
2
votes
1 answer

How does the read() function work? (What happens to the unread data in the buffer?)

I was trying to read input from the terminal using read() in a while loop as a condition, but the code doesn't get executed until the loop ends. Here is my code: #include int main(void) { char ch; while(read(STDIN_FILENO,&ch,1) ==…
Pradeep S
  • 17
  • 2
2
votes
1 answer

C implement like cat with robustness and efficiency

I want to learn to implement the function like cat, which just take input from a file and print to stdout. But I am not sure the line of write() is robust in all cases as it may write less than n. But I am not able to create a test case to make this…
user15483624
2
votes
2 answers

C's getopt not able to parse options at the end (or in between) of argv

I love getopt to parse options from the argv argument. Unfortunately I'm not able to make getopt parse options that are between nonoptions or at the end of argv. Example Program: #include #include int o_help = 0; int main(int…
2
votes
0 answers

Why the output of write function precedes the output of printf function?

I was trying to Implement my own printf function and I discovered this strange behavior, when you try to print something using printf() and after it you try to print something else using write(), the output of write() is printed before the output of…
Holy semicolon
  • 868
  • 1
  • 11
  • 27
1
2
3
11 12