-
Notifications
You must be signed in to change notification settings - Fork 0
/
5-1-large-file.c
49 lines (41 loc) · 1.44 KB
/
5-1-large-file.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*************************************************************************\
* Copyright (C) Michael Kerrisk, 2022. *
* *
* This program is free software. You may use, modify, and redistribute it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation, either version 3 or (at your option) any *
* later version. This program is distributed without any warranty. See *
* the file COPYING.gpl-v3 for details. *
\*************************************************************************/
/* Listing 5-3 */
/* large_file.c
Demonstrate the use of the (obsolete) Large File System API.
This program is Linux-specific.
*/
//#define _LARGEFILE64_SOURCE
#define _FILE_OFFSET_BITS 64
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
int
main(int argc, char *argv[])
{
int fd;
off_t off;
if (argc != 3 || strcmp(argv[1], "--help") == 0){
printf("%s pathname offset\n", argv[0]);
return 1;
}
fd = open(argv[1], O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
if (fd == -1)
perror("open64");
off = atoll(argv[2]);
if (lseek(fd, off, SEEK_SET) == -1)
perror("lseek64");
if (write(fd, "test", 4) == -1)
perror("write");
exit(EXIT_SUCCESS);
}