home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / filelock.prg < prev    next >
Text File  |  1993-10-14  |  2KB  |  82 lines

  1. /*
  2.  * File......: FILELOCK.PRG
  3.  * Author....: Martin Colloby
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Martin Colloby
  7.  * Date......: 18/4/93
  8.  * Revision..: 1.0
  9.  *
  10.  * This is an original work by Martin Colloby and is placed in the public
  11.  * domain.
  12.  *
  13.  * Modification history:
  14.  * ---------------------
  15.  *
  16.  * $Log$
  17.  *
  18.  */
  19.  
  20.  
  21. /*  $DOC$
  22.  *  $FUNCNAME$
  23.  *      GT_FILLOCK()
  24.  *  $CATEGORY$
  25.  *      General
  26.  *  $ONELINER$
  27.  *      Attempt to FLOCK() with optional retries
  28.  *  $SYNTAX$
  29.  *      GT_FilLock( nSeconds )
  30.  *  $ARGUMENTS$
  31.  *      nSeconds - Number of retries - 0 to retry indefinately
  32.  *  $RETURNS$
  33.  *      .T. if the file was locked
  34.  *      .F. if the file was not locked
  35.  *  $DESCRIPTION$
  36.  *      Attempts to FLOCK the current area.  If it fails, waits for a second
  37.  *      and tries again.  After nSeconds retries it fails.
  38.  *  $EXAMPLES$
  39.  *
  40.  *  $SEEALSO$
  41.  *
  42.  *  $INCLUDE$
  43.  *
  44.  *  $END$
  45.  */
  46.  
  47. *
  48. FUNCTION GT_FilLock( nSeconds )
  49.  
  50. /*****************************************************************************
  51.  Purpose - Attempt to FLOCK() with optional retries
  52.  Returns - .T. if lock applied, .F. otherwise
  53.  Author  - Martin Colloby
  54.  Created - 20/05/92
  55. ******************************************************************************
  56.  Parameters - nSeconds - Number of retries to make
  57.  Privates   - None
  58.  Locals     - lForever - If .T., loop forever
  59.  Externals  - None
  60. *****************************************************************************/
  61.  
  62. LOCAL lForever := (nSeconds == 0)
  63.  
  64. IF FLOCK()
  65.     * Locked
  66.     RETURN (.T.)
  67. ENDIF
  68.  
  69. DO WHILE (lForever .OR. nSeconds > 0)
  70.     * Wait 1/2 second
  71.     INKEY(.5)
  72.     nSeconds := nSeconds - .5
  73.     IF FLOCK()
  74.         * Locked
  75.         RETURN (.T.)
  76.     ENDIF
  77. ENDDO
  78.  
  79. * Not locked
  80. RETURN (.F.)
  81. *
  82.