Linux Open_() Problems

Linux specific forum
swhite
Enthusiast
Enthusiast
Posts: 726
Joined: Thu May 21, 2009 6:56 pm

Linux Open_() Problems

Post by swhite »

Hi

I am trying to understand how to use Linux functions in Purebasic. So I wanted to open a file and see if I could lock it. However, the File Descriptor returned from the open_() functions is always -1. There was one occasion when it was a positive value but I have not been able to repeat it. Can anyone see what is wrong with my code? I am new to Linux so I have lots to learn.

Code: Select all

ImportC ""
   flock.i(tnH.i,tnLock.i)
   errno_location() As "__errno_location"
EndImport

lcPath.s = GetCurrentDirectory()
Debug lcpath

lnF.i= open_(lcPath+"test.pid",O_CREAT + O_RDWR,"0666")

;lnF.i = CreateFile(1,lcPath+"test.pid",#PB_File_NoBuffering | #PB_Ascii)

Debug lnF

Structure Lock
   l_type.i
   l_whence.i
   l_start.i
   l_len.i
   l_pid.i
EndStructure

Define loLock.Lock

loLock\l_type = F_RDLCK   ; F_WRLCK = 1, F_UNLCK = 2, F_RDLCK = 0
loLock\l_whence = SEEK_SET ; SEEK_SET = 0
lolock\l_start = 0
loLock\l_len = 0
loLock\l_pid = getpid_()

lnLck.i = fcntl_(lnF,F_SETLCK,@loLock)
Debug PeekL(errno_location())

;lnLck.i = flock(lnID,1) ;LOCK_SH	1, LOCK_EX	2, LOCK_NB	4, LOCK_UN	8
Debug lnLck
Simon White
dCipher Computing