Project

General

Profile

Bug #55510 ยป write_test.c

Reproducer - Sachin Prabhu, 05/01/2022 02:02 PM

 
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>

int main( int argc, char **argv )
{
int fd;

if( argc < 2 ){
fprintf(stderr, "Usage %s <filename>\n\n",argv[0]);
exit(1);
}

if((fd = open( argv[1], O_CREAT| O_RDWR| O_EXCL, 0777)) == -1) {
fprintf(stderr,"Error opening file:%d: %s\n", errno, strerror(errno));
exit(2);
}

if(lseek(fd, 0xfffffff0000 - 1, SEEK_SET) == -1) {
fprintf(stderr,"Error seeking offset:%d: %s\n", errno, strerror(errno));
exit(2);
}
if(write(fd, "a", 1) == -1) {
fprintf(stderr,"Error writing:%d: %s\n", errno, strerror(errno));
exit(2);
}

fprintf(stderr, " -- Done\n");

return 0;
}


    (1-1/1)