🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #577

lockf - is it broken

#577
From: Bryan Thompson
Date: Wed, 08 Apr 1992 15:35
49 lines
1729 bytes
I am trying to port the Faircom ctree+ ISAM package to the next and I am  
encountering a problem with lockf() - basically, lockf() persists in claiming  
that it is being passed an invalid argument -- frankly it looks like lockf() is  
broken.

So, is lockf() broken?  If not, what can be done to make this code run?  I have  
included a small program with an abundance of trace statements and a sample of  
the output that it generates for me. I am using version 2.1 of the NeXT OS and  
the 'NeXT Release 2.0 (v31.1) -- GNU version 1.36' version of gcc.

------- cut here ---------
#include <stdio.h>
#include <sys/fcntl.h>
#include <stdlib.h>
#define BCREATE (O_RDWR | O_CREAT | O_EXCL)

void MyCreate(void)
{
int retval = open("tmp",BCREATE,0666);		/* Create file. */
perror("create:"); printf("retval = %d.\n", retval);
if (retval > -1) {							/* Open  
ok. */
	int lockval = lockf(retval,F_TLOCK,0L);	/* Attempt lock on file. */
	perror("lock:");	printf("lockval = %d.\n", lockval);
	if (lockval) printf("lock failed.\n");
	close(retval);
	} else {
	printf("create failed:");
	}
printf("done");
}

main()
{
MyCreate();
}
------ cut here ------

My output is:
create:: Error 0
retval = 3.
lock:: Invalid argument
lockval = -1.
lock failed.

This is aggravating, help is greatly appreatiated.

Bryan Thompson
bryan@ad.cise.nsf.gov
Technical Details
Message-ID: <1992Apr8.153515.3244@n1.nsf.gov>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!mips!darwin.sura.net!n1!news

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!mips!darwin.sura.net!n1!news
From: bryan@ad.cise.nsf.gov (Bryan Thompson)
Subject: lockf - is it broken
Message-ID: <1992Apr8.153515.3244@n1.nsf.gov>
Sender: news@n1.nsf.gov
Organization: National Science Foundation
Date: Wed, 8 Apr 1992 15:35:15 GMT