Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bf72a6d

Browse files
Feat: add syscall example file
1 parent af70c57 commit bf72a6d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Demo to show the write() system call
3+
* build: gcc syscall_ex.c -o syscall_ex
4+
* run: ./syscall_ex
5+
*
6+
*/
7+
#include <unistd.h> // for POSIX operation system API
8+
#include <stdio.h>
9+
#include <string.h>
10+
#define BUFFER_SIZE 100
11+
12+
int main()
13+
{
14+
ssize_t len; // to store the number of byte written from write() syscall
15+
size_t msg_len;
16+
char msg[] = "Hello, World! This message is written from write() system call\n";
17+
char buff[BUFFER_SIZE];
18+
19+
// copy the message to the buffer
20+
strncpy(buff, msg, sizeof(msg));
21+
msg_len = strlen(buff);
22+
23+
int fd = 1; // define file descriptor. 1 = standard output
24+
len = write(fd, buff, msg_len);
25+
26+
return 0;
27+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /