Mail Archives: djgpp-workers/1999/07/18/06:40:07
kant:/tmp> uname -a
Linux kant 2.0.33 #1 Fri Aug 21 06:21:28 CEST 1998 i586 unknown
kant:/tmp> ldd d
/lib/nfslock.so.0 => /lib/nfslock.so.0 (0x4000d000)
libc.so.6 => /lib/libc.so.6 (0x40012000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
kant:/tmp> touch /tmp/.aasas
kant:/tmp> ./d
Open done.
Write done (w = 19).
ftruncate done (ft = 0).
lseek returned 19.
kant:/tmp> ls -al /tmp/.aasas
-rw-r--r-- 1 martin users 2 Jul 18 12:37 /tmp/.aasas
Test program follows.
Welin, String Quartet No. 7,
MartinS
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(void)
{
int fd;
int ft;
int w;
char my_str[] = "This is my string.\n";
fd = open("/tmp/.aasas", O_WRONLY);
if( fd < 0 )
{
perror("open on /tmp/.aasas failed");
exit(1);
}
fprintf(stderr, "Open done.\n");
w = write(fd, my_str, strlen(my_str));
fprintf(stderr, "Write done (w = %d).\n", w);
ft = ftruncate(fd, 2);
if(ft < 0)
{
perror("ftruncate failed.\n");
}
fprintf(stderr, "ftruncate done (ft = %d).\n", ft);
ft = lseek(fd, 0, SEEK_CUR);
fprintf(stderr, "lseek returned %d.\n", ft);
return(0);
}
- Raw text -