?? read.c
字號:
/*** (c) 1992 Uwe C. Schroeder, Anwendungssysteme , Augsburg, Germany**** ** Permission to use, copy, and modify this software and its** documentation for non comercial purpose is hereby granted ** without fee, provided that** the above copyright notice appear in all copies and that both that** copyright notice and this permission notice appear in supporting** documentation, and that the name of Uwe C. Schroeder not be used in** advertising or publicity pertaining to distribution of the software without** specific, written prior permission. Uwe Schroeder makes no representations** about the suitability of this software for any purpose. It is provided** "as is" without express or implied warranty.** This software may not be sold or distributed with commercial products** ( this includes distribution "for users convenience" ) without prior** written permission by the author.**** UWE SCHROEDER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,** INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO** EVENT SHALL UWE SCHROEDER BE LIABLE FOR ANY SPECIAL, INDIRECT OR** CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,** DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER** TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR** PERFORMANCE OF THIS SOFTWARE.****** This is a alpha release, which means, that there are still several** known bugs.**** Please report bugs to:**** usys@phoenix.abg.sub.org***/#include <stdio.h>#include <sys/types.h>#include <fcntl.h>#include "vfax.h"extern int fd;/* reads a line of characters, terminated by a newline *//* returns number ob chars read (w/o zero) */int fdgets(buf, nbytes) char *buf; int nbytes;{ int i; char *bp; unsigned char ch; again: bp = buf; for (i = 0; i < nbytes; i++) { while(read(fd,&ch,1) < 1); if (ch == '\n' || ch == '\r') break; *bp++ = ch; } if(i<2) goto again; *bp = '\0'; return(i);}/* read with hang on tty line this works only in blocked read mode &~O_NDELAY*/intread_hang(buf,bytes) int bytes; char *buf;{ int i; char *bp; unsigned char ch; bp = buf; for (i = 0; i < bytes; i++) { if(read(fd,&ch,1)>0) *bp++ = ch; else goto end; } end: return(i);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -