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 pointer argv[];
00042 { int fd,stat;
00043   pointer buf;
00044   if (n==0 || n>2) error(E_MISMATCHARG);
00045   fd=getfd(argv[0]);
00046   buf=getbuf(n,argv[1],bufsize);
00047   stat=ioctl(fd,ctlcode,buf->c.str.chars);
00048   if (stat<0) return(makeint( (-errno)));
00049   else return(buf);}
00050 
00051 static pointer ioctl_int(n,argv,ctlcode)
00052 int n;
00053 pointer argv[];
00054 { int fd,stat,intarg;
00055   pointer buf;
00056   ckarg(2);
00057   fd=getfd(argv[0]);
00058   intarg=ckintval(argv[1]);
00059   stat=ioctl(fd,ctlcode, &intarg);
00060   if (stat<0) return(makeint(-errno));
00061   else return(makeint(intarg));}
00062 
00063 /********************************  obsolete interfaces
00064 
00065 pointer IOCTL_TIOCGETP(ctx,n,argv)
00066 register context *ctx;
00067 int n;
00068 pointer argv[];
00069 { return(ioctl_struct(n,argv,TIOCGETP,sizeof(struct sgttyb)));}
00070 
00071 pointer IOCTL_TIOCSETP(ctx,n,argv)
00072 register context *ctx;
00073 int n;
00074 pointer argv[];
00075 { ckarg(2);
00076   return(ioctl_struct(n,argv,TIOCSETP,sizeof(struct sgttyb)));}
00077 
00078 pointer IOCTL_TIOCSETN(ctx,n,argv)
00079 register context *ctx;
00080 int n;
00081 pointer argv[];
00082 { ckarg(2);
00083   return(ioctl_struct(n,argv,TIOCSETN,sizeof(struct sgttyb)));}
00084 
00085 pointer IOCTL_TIOCGETD(ctx,n,argv)
00086 register context *ctx;
00087 int n;
00088 pointer argv[];
00089 { return(ioctl_int(n,argv,TIOCGETD));}
00090 
00091 pointer IOCTL_TIOCSETD(ctx,n,argv)
00092 register context *ctx;
00093 int n;
00094 pointer argv[];
00095 { return(ioctl_int(n,argv,TIOCSETD));}
00096 
00097 pointer IOCTL_TIOCFLUSH(ctx,n,argv)
00098 register context *ctx;
00099 int n;
00100 pointer argv[];
00101 { return(ioctl_int(n,argv,TIOCFLUSH));}
00102 
00103 pointer IOCTL_TIOCGPGRP(ctx,n,argv)
00104 register context *ctx;
00105 int n;
00106 pointer argv[];
00107 { return(ioctl_int(n,argv,TIOCGPGRP));}
00108 
00109 pointer IOCTL_TIOCSPGRP(ctx,n,argv)
00110 register context *ctx;
00111 int n;
00112 pointer argv[];
00113 { return(ioctl_int(n,argv,TIOCSPGRP));}
00114 
00115 pointer IOCTL_TIOCOUTQ(ctx,n,argv)
00116 register context *ctx;
00117 int n;
00118 pointer argv[];
00119 { return(ioctl_int(n,argv,TIOCOUTQ));}
00120 
00121 pointer IOCTL_TIOCLBIS(ctx,n,argv)
00122 register context *ctx;
00123 int n;
00124 pointer argv[];
00125 { return(ioctl_int(n,argv,TIOCLBIS));}
00126 
00127 pointer IOCTL_TIOCLBIC(ctx,n,argv)
00128 register context *ctx;
00129 int n;
00130 pointer argv[];
00131 { return(ioctl_int(n,argv,TIOCLBIC));}
00132 
00133 pointer IOCTL_TIOCLSET(ctx,n,argv)
00134 register context *ctx;
00135 int n;
00136 pointer argv[];
00137 { return(ioctl_int(n,argv,TIOCLSET));}
00138 
00139 pointer IOCTL_TIOCLGET(ctx,n,argv)
00140 register context *ctx;
00141 int n;
00142 pointer argv[];
00143 { return(ioctl_int(n,argv,TIOCLGET));}
00144 
00145 
00146 **********************************************/
00147 
00148 /****************************************
00149 #if !Solaris2
00150 pointer IOCTL_FIONREAD(ctx,n,argv)
00151 register context *ctx;
00152 int n;
00153 pointer argv[];
00154 { return(ioctl_int(n,argv,FIONREAD));}
00155 
00156 pointer IOCTL_TIOCGETC(ctx,n,argv)
00157 register context *ctx;
00158 int n;
00159 pointer argv[];
00160 { return(ioctl_struct(n,argv,TIOCGETC,sizeof(struct tchars)));}
00161 
00162 pointer IOCTL_TIOCSETC(ctx,n,argv)
00163 register context *ctx;
00164 int n;
00165 pointer argv[];
00166 { ckarg(2);
00167   return(ioctl_struct(n,argv,TIOCSETC,sizeof(struct tchars)));}
00168 #endif
00169 ********************************************/
00170 
00171 
00172 #if !Darwin
00173 #if sun3 || sun4 || Linux || alpha || IRIX || Solaris2
00174 
00175 pointer IOCTL_TCGETS(ctx,n,argv)
00176 register context *ctx;
00177 int n;
00178 pointer argv[];
00179 { return(ioctl_struct(n,argv,TCGETS,sizeof(struct termios)));}
00180 
00181 pointer IOCTL_TCSETS(ctx,n,argv)
00182 register context *ctx;
00183 int n;
00184 pointer argv[];
00185 { return(ioctl_struct(n,argv,TCSETS,sizeof(struct termios)));}
00186 
00187 pointer IOCTL_TCSETSW(ctx,n,argv)
00188 register context *ctx;
00189 int n;
00190 pointer argv[];
00191 { return(ioctl_struct(n,argv,TCSETSW,sizeof(struct termios)));}
00192 
00193 pointer IOCTL_TCSETSF(ctx,n,argv)
00194 register context *ctx;
00195 int n;
00196 pointer argv[];
00197 { return(ioctl_struct(n,argv,TCSETSF,sizeof(struct termios)));}
00198 #endif
00199 
00200 pointer IOCTL_TCGETA(ctx,n,argv)
00201 register context *ctx;
00202 int n;
00203 pointer argv[];
00204 { return(ioctl_struct(n,argv,TCGETA,sizeof(struct termio)));}
00205 
00206 pointer IOCTL_TCSETA(ctx,n,argv)
00207 register context *ctx;
00208 int n;
00209 pointer argv[];
00210 { return(ioctl_struct(n,argv,TCSETA,sizeof(struct termio)));}
00211 
00212 pointer IOCTL_TCSETAF(ctx,n,argv)
00213 register context *ctx;
00214 int n;
00215 pointer argv[];
00216 { return(ioctl_struct(n,argv,TCSETAF,sizeof(struct termio)));}
00217 
00218 pointer IOCTL_TCSETAW(n,argv)
00219 int n;
00220 pointer argv[];
00221 { return(ioctl_struct(n,argv,TCSETAW,sizeof(struct termio)));}
00222 #endif
00223 
00224 pointer TCGETATTR(ctx,n,argv)
00225 register context *ctx;
00226 int n;
00227 pointer argv[];
00228 { int stat;
00229   pointer buf;
00230   ckarg2(1,2);
00231   buf=getbuf(n,argv[1],sizeof(struct termios));
00232   stat=tcgetattr(getfd(argv[0]),(struct termios *)buf->c.str.chars);
00233   if (stat<0) return(makeint(-errno)); else return(buf);}
00234 
00235 pointer TCSETATTR(ctx,n,argv)
00236 register context *ctx;
00237 int n;
00238 pointer argv[];
00239 { int stat,optact=0;
00240   pointer buf;
00241   ckarg2(1,3);
00242   buf=getbuf(n,argv[2],sizeof(struct termios));
00243   if (n>=2) optact=ckintval(argv[1]);
00244   stat=tcsetattr(getfd(argv[0]),optact,(struct termios *)buf->c.str.chars);
00245   if (stat<0) return(makeint(-errno)); else return(buf);}
00246 
00247 void eusioctl(ctx,mod)
00248 register context *ctx;
00249 register pointer mod;
00250 {
00251 /*********************** obsolete
00252   defunpkg(ctx,"TIOCGETP",mod,IOCTL_TIOCGETP,unixpkg);
00253   defunpkg(ctx,"TIOCSETP",mod,IOCTL_TIOCSETP,unixpkg);
00254   defunpkg(ctx,"TIOCSETN",mod,IOCTL_TIOCSETN,unixpkg);
00255   defunpkg(ctx,"TIOCGETD",mod,IOCTL_TIOCGETD,unixpkg);
00256   defunpkg(ctx,"TIOCFLUSH",mod,IOCTL_TIOCFLUSH,unixpkg);
00257   defunpkg(ctx,"TIOCGPGRP",mod,IOCTL_TIOCGPGRP,unixpkg);
00258   defunpkg(ctx,"TIOCSPGRP",mod,IOCTL_TIOCSPGRP,unixpkg);
00259   defunpkg(ctx,"TIOCOUTQ",mod,IOCTL_TIOCOUTQ,unixpkg);
00260   defunpkg(ctx,"TIOCLBIS",mod,IOCTL_TIOCLBIS,unixpkg);
00261   defunpkg(ctx,"TIOCLBIC",mod,IOCTL_TIOCLBIC,unixpkg);
00262   defunpkg(ctx,"TIOCLSET",mod,IOCTL_TIOCLSET,unixpkg);
00263   defunpkg(ctx,"TIOCLGET",mod,IOCTL_TIOCLGET,unixpkg);
00264 *************************************/
00265 
00266 /*********************************** obsolete
00267 #if !Solaris2
00268   defunpkg(ctx,"FIONREAD",mod,IOCTL_FIONREAD,unixpkg);
00269   defunpkg(ctx,"TIOCGETC",mod,IOCTL_TIOCGETC,unixpkg);
00270   defunpkg(ctx,"TIOCSETC",mod,IOCTL_TIOCSETC,unixpkg);
00271 #endif
00272 *********************************************/
00273 
00274 #if !Darwin
00275 #if sun3 || sun4 || Linux || alpha || IRIX || Solaris2
00276   defunpkg(ctx,"TCGETS",mod,IOCTL_TCGETS,unixpkg);
00277   defunpkg(ctx,"TCSETS",mod,IOCTL_TCSETS,unixpkg);
00278   defunpkg(ctx,"TCSETSW",mod,IOCTL_TCSETSW,unixpkg);
00279   defunpkg(ctx,"TCSETSF",mod,IOCTL_TCSETSF,unixpkg);
00280 #endif
00281   defunpkg(ctx,"TCGETA",mod,IOCTL_TCGETA,unixpkg);
00282   defunpkg(ctx,"TCSETA",mod,IOCTL_TCSETA,unixpkg);
00283   defunpkg(ctx,"TCSETAW",mod,IOCTL_TCSETAW,unixpkg);
00284   defunpkg(ctx,"TCSETAF",mod,IOCTL_TCSETAF,unixpkg);
00285 #endif
00286   defunpkg(ctx,"TCGETATTR",mod,TCGETATTR,unixpkg);
00287   defunpkg(ctx,"TCSETATTR",mod,TCSETATTR,unixpkg);
00288 /*  printf("eusioctl: TCGETS=%x\n", TCGETS); */
00289   }


euslisp
Author(s): Toshihiro Matsui
autogenerated on Thu Sep 3 2015 10:36:19