From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29325 invoked by alias); 14 Jan 2002 21:24:25 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 29281 invoked from network); 14 Jan 2002 21:24:21 -0000 Received: from unknown (HELO bloch.anu.edu.au) (150.203.35.220) by sources.redhat.com with SMTP; 14 Jan 2002 21:24:21 -0000 Received: from localhost (chris@localhost) by bloch.anu.edu.au (8.11.5/8.11.5) with ESMTP id g0ELKh104711 for ; Tue, 15 Jan 2002 08:20:43 +1100 (EST) X-Authentication-Warning: bloch.anu.edu.au: chris owned process doing -bs Date: Mon, 14 Jan 2002 13:24:00 -0000 From: Chris Blake X-Sender: chris@bloch To: gcc-help@gcc.gnu.org Subject: File locking with gcc 3 Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-SW-Source: 2002-01/txt/msg00142.txt.bz2 How does one do Posix file locking with gcc3 / libstdc++-v3? The program is written in C++, and I'm trying to compile it under Solaris 8. It is a simple booking system where the program locks a booking data file, reads the last request number from it, then writes a new booking with an incremented request number before releasing the lock. The following fragment used to compile under g++ 2.95... ----------------------- #define GCC3 1 #if GCC3 // mods for gcc 3 #include #include #include #include #include using namespace std; #else #include #include // for file locking #include #include #endif int JobRequest::getlock() { struct flock lock; fd = jobfile.rdbuf()->fd(); lock.l_type = F_WRLCK; lock.l_start = 0; lock.l_whence = SEEK_SET; lock.l_len = 0; return( fcntl(fd, F_SETLK, &lock) ); } ----------------------- ....but with g++ 3.0.2 I get request.cpp: In member function `int JobRequest::getlock()': request.cpp:70: no matching function for call to `std::basic_filebuf >::fd()' I've also tried replacing the body of the function with the line return( fcntl(fd, F_SETLKW, file_lock(F_WRLCK, SEEK_SET))); but g++ then gives the error... request.cpp:79: `file_lock' undeclared (first use this function) ...and file_lock() does not appear to be defined in any of the system include files. Perhaps there is another method of locking files? thanks, Chris Blake