/*
Copyright (c) 1993 Xerox Corporation.  All rights reserved.
*/
/*
$Id$

$Date$
 *
 * PCR - I/O local (per-thread) descriptor support
 *
 */

#ifndef	←←PCR←IOLcl←h
#define ←←PCR←IOLcl←h 1

#include <config/PCR←StdTypes.h>
#include <th/PCR←ThData.h>
#include <io/PCR←IOGbl.h>
#include <limits.h>

typedef volatile struct PCR←IOLcl←DERep * PCR←IOLcl←DEPtr;

struct PCR←IOLcl←DERep {
    /* global fildes (>0) or empty (0) */
        PCR←ERes lde←gfd;
    /* per-descriptor data for fcntl */
        int lde←fcntlFD;
};

typedef volatile struct PCR←IOLcl←DERep PCR←IOLcl←DE;

#define PCR←IOLcl←DE←null	{ 0, 0 }


typedef volatile struct PCR←IOLcl←DataRep * PCR←IOLcl←DataPtr;

struct PCR←IOLcl←DataRep {
    /* per-thread working directory */
        const char *ld←wd;
    /* per-thread umask */
        mode←t ld←umask;
    /* number of open files */
        int ld←nOpen;
    /* data per open file */
        PCR←IOLcl←DE ld←lde[PCR←POSIX←OPEN←MAX];
};

typedef struct PCR←IOLcl←DataRep PCR←IOLcl←Data;

#define PCR←IOLcl←ld	(*( (PCR←IOLcl←Data **) \
	(&( PCR←ThData←Get()->td←←ioData )) ))

extern PCR←IOLcl←DEPtr
PCR←IOLcl←DEPtr←FromFD(int fd);

#define PCR←IOLcl←DEPtr←←FromFD(fd) (&(PCR←IOLcl←ld->ld←lde[fd]))
#define PCR←IOLcl←DEPtr←FromFD	PCR←IOLcl←DEPtr←←FromFD

extern int
PCR←IOLcl←DEPtr←ToFD(PCR←IOLcl←DEPtr lde);

#define PCR←IOLcl←DEPtr←←ToFD(lde) (\
	(lde) - PCR←IOLcl←DEPtr←←FromFD(0) )
#define PCR←IOLcl←DEPtr←ToFD	PCR←IOLcl←DEPtr←←ToFD


extern int
PCR←IOLcl←DEPtr←ToGFD(PCR←IOLcl←DEPtr lde);

#define PCR←IOLcl←DEPtr←←ToGFD(lde) (\
	(lde)->lde←gfd )
#define PCR←IOLcl←DEPtr←ToGFD	PCR←IOLcl←DEPtr←←ToGFD
/*
    For internal use -- doesn't bump ref count.
*/


extern PCR←IOLcl←DEPtr
PCR←IOLcl←FindUnusedDEPtr(PCR←IOLcl←DEPtr lde);
/*
    Return an unused local descriptor entry,
      with fildes value >= lde if lde is not NIL.
    Return NIL if none available.
    Not reliable if signal might be delivered.
*/

extern void
PCR←IOLcl←AdjustNOpen(int delta);

#define PCR←IOLcl←←AdjustNOpen(delta) {\
	PCR←IOLcl←ld->ld←nOpen += (delta); }
#define PCR←IOLcl←AdjustNOpen	PCR←IOLcl←←AdjustNOpen

/*
    Adjust count of open local descriptors.
*/


/*
 * Initialization
 *
 * Called from PCR←IOImpl.c
 */

extern PCR←ERes PCR←IOLcl←Setup(void);

extern PCR←ERes PCR←IOLcl←Run(void);


#endif /* ! ←←PCR←IOLcl←h */

/*
$Log$
*/