1N/A * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. 1N/A * All rights reserved. 1N/A * Copyright (c) 1990, 1993 1N/A * The Regents of the University of California. All rights reserved. 1N/A * This code is derived from software contributed to Berkeley by 1N/A * By using this file, you agree to the terms and conditions set 1N/A * forth in the LICENSE file which can be found at the top level of 1N/A * the sendmail distribution. 1N/A#
pragma ident "%Z%%M% %I% %E% SMI" 1N/A** SM_IO_FGETS -- get a string from a file 1N/A** Read at most n-1 characters from the given file. 1N/A** Stop when a newline has been read, or the count ('n') runs out. 1N/A** fp -- the file to read from 1N/A** timeout -- time to complete reading the string in milliseconds 1N/A** buf -- buffer to place read string in 1N/A** n -- size of 'buf' 1N/A** success: returns value of 'buf' 1N/A** failure: NULL (no characters were read) 1N/A** timeout: NULL and errno set to EAGAIN 1N/A** may move the file pointer 1N/A register unsigned char *p, *t;
1N/A if (n <= 0)
/* sanity check */ 1N/A n--;
/* leave space for NUL */ 1N/A /* If the buffer is empty, refill it. */ 1N/A ** Timeout is only passed if we can't get the data 1N/A ** from the buffer (which is counted as immediately). 1N/A ** Scan through at most n bytes of the current buffer, 1N/A ** looking for '\n'. If found, copy up to and including 1N/A ** newline, and stop. Otherwise, copy entire chunk