Lines Matching defs:fd
181 int id1, id2, r=0, n, fd;
182 if((fd=open(name, O_RDONLY)) < 0)
184 if((n = read(fd, logbuf,len-1)) < 0)
206 close(fd);
230 register int fd;
266 if((fd=open(cp,O_BINARY|O_APPEND|O_RDWR|O_CREAT,histmode))>=0)
268 hsize=lseek(fd,(off_t)0,SEEK_END);
270 if((unsigned)fd <=2)
273 if((n=fcntl(fd,F_DUPFD,10))>=0)
275 close(fd);
276 fd=n;
280 if(hsize && hist_check(fd))
282 close(fd);
286 fd = -1;
288 if(fd < 0)
297 fd = open(fname,O_BINARY|O_APPEND|O_CREAT|O_RDWR,S_IRUSR|S_IWUSR);
300 if(fd<0)
303 fcntl(fd,F_SETFD,FD_CLOEXEC);
311 close(fd);
318 hp->histfp= sfnew(NIL(Sfio_t*),hp->histbuff,HIST_BSIZE,fd,SF_READ|SF_WRITE|SF_APPENDWR|SF_SHARE);
362 if(hist_clean(fd) && hist_start>1 && hsize > HIST_MAX)
385 if((fd=sh_open(buff,O_BINARY|O_WRONLY|O_APPEND|O_CREAT,S_IRUSR|S_IWUSR))>=0 && fd < 10)
388 if((n = sh_fcntl(fd,F_DUPFD, 10)) >= 0)
390 sh_close(fd);
391 fd = n;
394 if(fd>=0)
396 fcntl(fd,F_SETFD,FD_CLOEXEC);
398 hp->auditfp = sfnew((Sfio_t*)0,NULL,-1,fd,SF_WRITE);
436 static int hist_check(register int fd)
439 lseek(fd,(off_t)0,SEEK_SET);
440 if((read(fd,(char*)magic,2)!=2) || (magic[0]!=HIST_UNDO))
448 static int hist_clean(int fd)
451 return(fstat(fd,&statb)>=0 && (time((time_t*)0)-statb.st_mtime) >= HIST_RECENT);
470 int fd;
484 fd = open(tmpname,O_RDONLY);
485 sfsetfd(hist_old->histfp,fd);
729 int fd = open(hp->histname,O_RDWR);
730 if(fd>=0)
733 write(fd,(char*)hist_stamp,2);
734 write(fd,buff,HIST_MARKSZ);
735 close(fd);