[prev in list] [next in list] [prev in thread] [next in thread]
List: aix-l
Subject: Why is this not working under AIX 4.x
From: Mario Dupuis <Mario.Dupuis () MFG ! CANADAIR ! CA>
Date: 1998-03-31 20:04:55
[Download RAW message or body]
Anyone knows why this piece of code is working under AIX 3.2.5
and not 4.1.5
I use this to test file locking related problems ...
It try's to get a lock and then reads the first 10 char of
a file called testfile.
Under 3.2.5 it works ...
But under AIX 4.1.5
it stops with this error
Error in lockf : Bad file number
--------------------
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
main()
{ int fd, n;
char buff[10];
if ((fd = open("testfile",O_EXCL)) < 0)
fprintf(stderr,"can't open testfile\n");
lseek(fd, 0, 0); /* rewind before lockf */
/* 0 : lock entire file */
if (lockf(fd,F_LOCK,0) == -1) {
fprintf(stderr,"can't F_LOCK\n");
perror("Error in lockf ");
}
if ((n = read(fd, buff, 10)) <= 0)
fprintf(stderr,"read error\n");
if ((write(1,buff, n)) != n)
fprintf(stderr,"write error on stdout\n");
lseek(fd, 0, 0);
if (lockf(fd,F_ULOCK,0) == -1)
fprintf(stderr,"can't F_ULOCK\n");
close(fd);
}
--
+---------------------------------------------------------------------+
| Mailto: Mario.Dupuis@mfg.canadair.ca Phone : (514) 855-5001 #51720 |
| System Administrator/BAG Fax : (514) 855-2157 |
| Hiroshima 45 -- Chernobyl 86 -- Windows 95 |
+---------------------------------------------------------------------+
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic