eusioctl.c
Go to the documentation of this file.
00001 /****************************************************************/
00002 /* ioctl.c
00003 /*   ioctl interface for euslisp
00004 /*   1988Mar23
00005 /*   Copyright(c)1988 Toshihiro MATSUI, Electrotechnical Laboratory
00006 /****************************************************************/
00007 static char *rcsid="@(#)$Id$";
00008 #include <ctype.h>
00009 #include <sys/termios.h>
00010 #ifndef Darwin
00011 #include <termio.h>
00012 #endif
00013 /*  #include <sgtty.h>  */
00014 
00015 #undef MAX
00016 #undef MIN
00017 #undef VMIN
00018 #undef VMAX
00019 #include "eus.h"
00020 
00021 extern int errno;
00022 
00023 static int getfd(x)
00024 pointer x;
00025 { if (isint(x)) return(intval(x));
00026   else if (isflt(x)) error(E_NOINT);
00027   else if (pisiostream(x)) x=x->c.iostream.in;
00028   else if (!pisfilestream(x)) error(E_STREAM);
00029   return(intval(x->c.fstream.fd));}
00030 
00031 static pointer getbuf(n,x,bufsize)
00032 int n,bufsize;
00033 pointer x;
00034 { if (n<=1) x=makebuffer(bufsize);
00035   else if (!isstring(x)) error(E_NOSTRING);
00036   else if (strlength(x)<bufsize) error(E_VECINDEX);
00037   return(x);}
00038 
00039 static pointer ioctl_struct(n,argv,ctlcode,bufsize)
00040 int n,bufsize;
00041 unsigned long  ctlcode;
00042 pointer argv[];
00043 { int fd,stat;
00044   pointer buf;
00045   if (n==0 || n>2) error(E_MISMATCHARG);
00046   fd=getfd(argv[0]);
00047   buf=getbuf(n,argv[1],bufsize);
00048   stat=ioctl(fd,ctlcode,buf->c.str.chars);
00049   if (stat<0) return(makeint( (-errno)));
00050   else return(buf);}
00051 
00052 static pointer ioctl_int(n,argv,ctlcode)
00053 int n;
00054 unsigned long  ctlcode;
00055 pointer argv[];
00056 { int fd,stat,intarg;
00057   pointer buf;
00058   ckarg(2);
00059   fd=getfd(argv[0]);
00060   intarg=ckintval(argv[1]);
00061   stat=ioctl(fd,ctlcode, &intarg);
00062   if (stat<0) return(makeint(-errno));
00063   else return(makeint(intarg));}
00064 
00065 /********************************  obsolete interfaces
00066 
00067 pointer IOCTL_TIOCGETP(ctx,n,argv)
00068 register context *ctx;
00069 int n;
00070 pointer argv[];
00071 { return(ioctl_struct(n,argv,TIOCGETP,sizeof(struct sgttyb)));}
00072 
00073 pointer IOCTL_TIOCSETP(ctx,n,argv)
00074 register context *ctx;
00075 int n;
00076 pointer argv[];
00077 { ckarg(2);
00078   return(ioctl_struct(n,argv,TIOCSETP,sizeof(struct sgttyb)));}
00079 
00080 pointer IOCTL_TIOCSETN(ctx,n,argv)
00081 register context *ctx;
00082 int n;
00083 pointer argv[];
00084 { ckarg(2);
00085   return(ioctl_struct(n,argv,TIOCSETN,sizeof(struct sgttyb)));}
00086 
00087 pointer IOCTL_TIOCGETD(ctx,n,argv)
00088 register context *ctx;
00089 int n;
00090 pointer argv[];
00091 { return(ioctl_int(n,argv,TIOCGETD));}
00092 
00093 pointer IOCTL_TIOCSETD(ctx,n,argv)
00094 register context *ctx;
00095 int n;
00096 pointer argv[];
00097 { return(ioctl_int(n,argv,TIOCSETD));}
00098 
00099 pointer IOCTL_TIOCFLUSH(ctx,n,argv)
00100 register context *ctx;
00101 int n;
00102 pointer argv[];
00103 { return(ioctl_int(n,argv,TIOCFLUSH));}
00104 
00105 pointer IOCTL_TIOCGPGRP(ctx,n,argv)
00106 register context *ctx;
00107 int n;
00108 pointer argv[];
00109 { return(ioctl_int(n,argv,TIOCGPGRP));}
00110 
00111 pointer IOCTL_TIOCSPGRP(ctx,n,argv)
00112 register context *ctx;
00113 int n;
00114 pointer argv[];
00115 { return(ioctl_int(n,argv,TIOCSPGRP));}
00116 
00117 pointer IOCTL_TIOCOUTQ(ctx,n,argv)
00118 register context *ctx;
00119 int n;
00120 pointer argv[];
00121 { return(ioctl_int(n,argv,TIOCOUTQ));}
00122 
00123 pointer IOCTL_TIOCLBIS(ctx,n,argv)
00124 register context *ctx;
00125 int n;
00126 pointer argv[];
00127 { return(ioctl_int(n,argv,TIOCLBIS));}
00128 
00129 pointer IOCTL_TIOCLBIC(ctx,n,argv)
00130 register context *ctx;
00131 int n;
00132 pointer argv[];
00133 { return(ioctl_int(n,argv,TIOCLBIC));}
00134 
00135 pointer IOCTL_TIOCLSET(ctx,n,argv)
00136 register context *ctx;
00137 int n;
00138 pointer argv[];
00139 { return(ioctl_int(n,argv,TIOCLSET));}
00140 
00141 pointer IOCTL_TIOCLGET(ctx,n,argv)
00142 register context *ctx;
00143 int n;
00144 pointer argv[];
00145 { return(ioctl_int(n,argv,TIOCLGET));}
00146 
00147 
00148 **********************************************/
00149 
00150 /****************************************
00151 #if !Solaris2
00152 pointer IOCTL_FIONREAD(ctx,n,argv)
00153 register context *ctx;
00154 int n;
00155 pointer argv[];
00156 { return(ioctl_int(n,argv,FIONREAD));}
00157 
00158 pointer IOCTL_TIOCGETC(ctx,n,argv)
00159 register context *ctx;
00160 int n;
00161 pointer argv[];
00162 { return(ioctl_struct(n,argv,TIOCGETC,sizeof(struct tchars)));}
00163 
00164 pointer IOCTL_TIOCSETC(ctx,n,argv)
00165 register context *ctx;
00166 int n;
00167 pointer argv[];
00168 { ckarg(2);
00169   return(ioctl_struct(n,argv,TIOCSETC,sizeof(struct tchars)));}
00170 #endif
00171 ********************************************/
00172 
00173 
00174 #if !Darwin
00175 #if sun3 || sun4 || Linux || alpha || IRIX || Solaris2
00176 
00177 pointer IOCTL_TCGETS(ctx,n,argv)
00178 register context *ctx;
00179 int n;
00180 pointer argv[];
00181 { return(ioctl_struct(n,argv,TCGETS,sizeof(struct termios)));}
00182 
00183 pointer IOCTL_TCSETS(ctx,n,argv)
00184 register context *ctx;
00185 int n;
00186 pointer argv[];
00187 { return(ioctl_struct(n,argv,TCSETS,sizeof(struct termios)));}
00188 
00189 pointer IOCTL_TCSETSW(ctx,n,argv)
00190 register context *ctx;
00191 int n;
00192 pointer argv[];
00193 { return(ioctl_struct(n,argv,TCSETSW,sizeof(struct termios)));}
00194 
00195 pointer IOCTL_TCSETSF(ctx,n,argv)
00196 register context *ctx;
00197 int n;
00198 pointer argv[];
00199 { return(ioctl_struct(n,argv,TCSETSF,sizeof(struct termios)));}
00200 #endif
00201 
00202 pointer IOCTL_TCGETA(ctx,n,argv)
00203 register context *ctx;
00204 int n;
00205 pointer argv[];
00206 { return(ioctl_struct(n,argv,TCGETA,sizeof(struct termio)));}
00207 
00208 pointer IOCTL_TCSETA(ctx,n,argv)
00209 register context *ctx;
00210 int n;
00211 pointer argv[];
00212 { return(ioctl_struct(n,argv,TCSETA,sizeof(struct termio)));}
00213 
00214 pointer IOCTL_TCSETAF(ctx,n,argv)
00215 register context *ctx;
00216 int n;
00217 pointer argv[];
00218 { return(ioctl_struct(n,argv,TCSETAF,sizeof(struct termio)));}
00219 
00220 pointer IOCTL_TCSETAW(n,argv)
00221 int n;
00222 pointer argv[];
00223 { return(ioctl_struct(n,argv,TCSETAW,sizeof(struct termio)));}
00224 #endif
00225 
00226 pointer TCGETATTR(ctx,n,argv)
00227 register context *ctx;
00228 int n;
00229 pointer argv[];
00230 { int stat;
00231   pointer buf;
00232   ckarg2(1,2);
00233   buf=getbuf(n,argv[1],sizeof(struct termios));
00234   stat=tcgetattr(getfd(argv[0]),(struct termios *)buf->c.str.chars);
00235   if (stat<0) return(makeint(-errno)); else return(buf);}
00236 
00237 pointer TCSETATTR(ctx,n,argv)
00238 register context *ctx;
00239 int n;
00240 pointer argv[];
00241 { int stat,optact=0;
00242   pointer buf;
00243   ckarg2(1,3);
00244   buf=getbuf(n,argv[2],sizeof(struct termios));
00245   if (n>=2) optact=ckintval(argv[1]);
00246   stat=tcsetattr(getfd(argv[0]),optact,(struct termios *)buf->c.str.chars);
00247   if (stat<0) return(makeint(-errno)); else return(buf);}
00248 
00249 void eusioctl(ctx,mod)
00250 register context *ctx;
00251 register pointer mod;
00252 {
00253 /*********************** obsolete
00254   defunpkg(ctx,"TIOCGETP",mod,IOCTL_TIOCGETP,unixpkg);
00255   defunpkg(ctx,"TIOCSETP",mod,IOCTL_TIOCSETP,unixpkg);
00256   defunpkg(ctx,"TIOCSETN",mod,IOCTL_TIOCSETN,unixpkg);
00257   defunpkg(ctx,"TIOCGETD",mod,IOCTL_TIOCGETD,unixpkg);
00258   defunpkg(ctx,"TIOCFLUSH",mod,IOCTL_TIOCFLUSH,unixpkg);
00259   defunpkg(ctx,"TIOCGPGRP",mod,IOCTL_TIOCGPGRP,unixpkg);
00260   defunpkg(ctx,"TIOCSPGRP",mod,IOCTL_TIOCSPGRP,unixpkg);
00261   defunpkg(ctx,"TIOCOUTQ",mod,IOCTL_TIOCOUTQ,unixpkg);
00262   defunpkg(ctx,"TIOCLBIS",mod,IOCTL_TIOCLBIS,unixpkg);
00263   defunpkg(ctx,"TIOCLBIC",mod,IOCTL_TIOCLBIC,unixpkg);
00264   defunpkg(ctx,"TIOCLSET",mod,IOCTL_TIOCLSET,unixpkg);
00265   defunpkg(ctx,"TIOCLGET",mod,IOCTL_TIOCLGET,unixpkg);
00266 *************************************/
00267 
00268 /*********************************** obsolete
00269 #if !Solaris2
00270   defunpkg(ctx,"FIONREAD",mod,IOCTL_FIONREAD,unixpkg);
00271   defunpkg(ctx,"TIOCGETC",mod,IOCTL_TIOCGETC,unixpkg);
00272   defunpkg(ctx,"TIOCSETC",mod,IOCTL_TIOCSETC,unixpkg);
00273 #endif
00274 *********************************************/
00275 
00276 #if !Darwin
00277 #if sun3 || sun4 || Linux || alpha || IRIX || Solaris2
00278   defunpkg(ctx,"TCGETS",mod,IOCTL_TCGETS,unixpkg);
00279   defunpkg(ctx,"TCSETS",mod,IOCTL_TCSETS,unixpkg);
00280   defunpkg(ctx,"TCSETSW",mod,IOCTL_TCSETSW,unixpkg);
00281   defunpkg(ctx,"TCSETSF",mod,IOCTL_TCSETSF,unixpkg);
00282 #endif
00283   defunpkg(ctx,"TCGETA",mod,IOCTL_TCGETA,unixpkg);
00284   defunpkg(ctx,"TCSETA",mod,IOCTL_TCSETA,unixpkg);
00285   defunpkg(ctx,"TCSETAW",mod,IOCTL_TCSETAW,unixpkg);
00286   defunpkg(ctx,"TCSETAF",mod,IOCTL_TCSETAF,unixpkg);
00287 #endif
00288   defunpkg(ctx,"TCGETATTR",mod,TCGETATTR,unixpkg);
00289   defunpkg(ctx,"TCSETATTR",mod,TCSETATTR,unixpkg);
00290 /*  printf("eusioctl: TCGETS=%x\n", TCGETS); */
00291   }


euslisp
Author(s): Toshihiro Matsui
autogenerated on Thu Jun 6 2019 18:05:53