This is device.c in view mode; [Download] [Up]
/*********************************************************************/
/* */
/* Programmer: */
/* Olaf Mueller <olaf@orest.escape.de> */
/* */
/* Purpose: */
/* Answering Machine */
/* open, close, lock, unlock the device */
/* */
/* History: */
/* 29-08-96 Initial Release Olaf Mueller */
/* */
/* Notes: */
/* */
/*********************************************************************/
#include <libc.h>
#include "device.h"
#define LOCKNAME "/usr/spool/uucp/LCK/LCK.."
int openDevice (char *devicetype,char port)
{
char devicename [MAXPATHLEN+1] ;
sprintf (devicename,"/dev/%s%c",devicetype,port) ;
return open (devicename,O_RDWR,0) ;
}
int initDevice (int line,int baud)
{
struct sgttyb tdis ;
ioctl (line,TIOCGETP,&tdis) ;
tdis.sg_ispeed = tdis.sg_ospeed = baud ;
tdis.sg_flags = RAW | TANDEM ;
ioctl (line,TIOCSETP,&tdis) ; /* set baud rate and raw mode */
ioctl (line,TIOCCDTR,NULL) ; /* reset DataTerminalReady */
usleep (100000L) ;
ioctl (line,TIOCSDTR,NULL) ; /* set DataTerminalReady */
usleep (1000000L) ;
fcntl (line,F_SETFL,(fcntl(line,F_GETFL,0))&~O_NDELAY) ;
return 0 ;
}
/*
* returns zero if the operation succeeds, -1 if it fails
*/
int lockDevice (char *devicetype,char port)
{
char filename [MAXPATHLEN+1] , pidstr [20] ;
int fd , len , rc = -1 ;
sprintf (filename,"%s%s%c",LOCKNAME,devicetype,port) ;
if ((fd = open(filename,O_WRONLY|O_CREAT|O_EXCL,0644)) > 0)
{
sprintf (pidstr,"%d\n",getpid()) ;
len = strlen (pidstr) ;
if (write(fd,pidstr,len) == len)
rc = 0 ;
close (fd) ;
}
return rc ;
}
/*
* returns zero if the operation succeeds, nonzero if it fails
*/
int unlockDevice (char *devicetype,char port)
{
char filename [MAXPATHLEN+1] ;
sprintf (filename,"%s%s%c",LOCKNAME,devicetype,port) ;
return remove (filename) ;
}
/*
* returns zero if the operation succeeds, nonzero if it fails
*/
int deviceLocked (char *devicetype,char port)
{
char filename [MAXPATHLEN+1] ;
sprintf (filename,"%s%s%c",LOCKNAME,devicetype,port) ;
return access (filename,F_OK) ;
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.