home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
lan
/
semaph
/
sema.c
< prev
next >
Wrap
Text File
|
1988-02-09
|
4KB
|
145 lines
/*
** SEMA.C - Novell NetWare Semaphore Function Call's
**
** Written by: Tom Scribner
** Date: November 18, 1987
**
** Description: These functions provide a application to use
** NetWare's semaphore's for various uses.
** Included are open, examine, and close a semaphore.
** See SEMA.DOC for a more complete description of
** these functions.
**
** History:
** 11/18/87 tes Initial Release
** 02/09/87 tes Released to public domain
**
*/
#include <dos.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "sema.h"
#define SEMA_CALL 0xC5
#define OPEN_SEMAPHORE 0x00
#define EXAMINE_SEMAPHORE 0x01
#define CLOSE_SEMAPHORE 0x04
#define MAKELONG(a,b) \
( (long) ( ((unsigned) a) | ((unsigned long)((unsigned)b)) << 16))
#define HIBYTE(a) ( (unsigned)(a) )
#define LOBYTE(a) ( (unsigned)( a >> 16 ) )
/* --------------------------------------------------------------- */
/* O P E N A S E M A P H O R E */
/* --------------------------------------------------------------- */
long
#ifdef MSC5
OpenSemaphore( char *SName, unsigned int InitVal, int *OpenCount )
#else
OpenSemaphore( SName, InitVal, OpenCount )
char *SName;
unsigned int InitVal;
int *OpenCount;
#endif
{
union REGS inregs,outregs;
struct SREGS segregs;
char buffer[127];
char far *lpBuffer = buffer;
long sema_handle;
int i = 0;
inregs.h.ah = SEMA_CALL;
inregs.h.al = OPEN_SEMAPHORE;
/* first char in buffer contains the length of the semaphore */
buffer[i++] = (char)strlen(SName);
while(*SName)
buffer[i++] = *SName++;
segregs.ds = FP_SEG(lpBuffer);
inregs.x.dx = FP_OFF(lpBuffer);
inregs.h.ch = (unsigned char )InitVal;
intdosx(&inregs,&outregs,&segregs);
if( outregs.h.al == 0){
sema_handle = MAKELONG(outregs.x.cx,outregs.x.dx);
*OpenCount = outregs.h.bl;
}else{
sema_handle = (long)ERROR;
*OpenCount = 0;
NetError = outregs.h.al;
}
return(sema_handle);
}
/* --------------------------------------------------------------- */
/* E X A M I N E A S E M A P H O R E */
/* --------------------------------------------------------------- */
int
#ifdef MSC5
ExamineSemaphore( long handle )
#else
ExamineSemaphore( handle )
long handle;
#endif
{
union REGS inregs,outregs;
int ret_val;
inregs.h.ah = SEMA_CALL;
inregs.h.al = EXAMINE_SEMAPHORE;
inregs.x.cx = HIBYTE( handle );
inregs.x.dx = LOBYTE( handle );
intdos(&inregs,&outregs);
if( outregs.h.al == 0){
NetError = 0;
ret_val = outregs.h.dl;
}else{
NetError = outregs.h.al;
ret_val = ERROR;
}
return( ret_val );
}
/* --------------------------------------------------------------- */
/* C L O S E A S E M A P H O R E */
/* --------------------------------------------------------------- */
int
#ifdef MSC5
CloseSemaphore( long handle )
#else
CloseSemaphore( handle )
long handle;
#endif
{
union REGS inregs,outregs;
int ret_val;
inregs.h.ah = SEMA_CALL;
inregs.h.al = CLOSE_SEMAPHORE;
inregs.x.cx = HIBYTE( handle );
inregs.x.dx = HIBYTE( handle );
intdos(&inregs,&outregs);
if( outregs.h.al != 0){
NetError = outregs.h.al;
ret_val = ERROR;
}else{
NetError = 0;
ret_val = (int)outregs.h.al;
}
return( ret_val );
}