Esempio n. 1
0
static __inline int
convert_char(FILE *fp, char * p, int width)
{
	int n;

	if (p == SUPPRESS_PTR) {
		size_t sum = 0;
		for (;;) {
			if ((n = fp->_r) < width) {
				sum += n;
				width -= n;
				fp->_p += n;
				if (__srefill(fp)) {
					if (sum == 0)
						return (-1);
					break;
				}
			} else {
				sum += width;
				fp->_r -= width;
				fp->_p += width;
				break;
			}
		}
		return (sum);
	} else {
		size_t r = __fread(p, 1, width, fp);

		if (r == 0)
			return (-1);
		return (r);
	}
}
/*-------------------------------------------
| Name:fgetc
| Description:
| Parameters:
| Return Type:
| Comments:
| See:
---------------------------------------------*/
int __fgetc(FILE *fp){
   int ch;

   __thr_safe_lock(fp);

   if (fp->mode & __MODE_WRITING)
      __fflush(fp);
#if __MODE_IOTRAN
try_again:
#endif
   /* Can't read or there's been an EOF or error then return EOF */
   if ((fp->mode & (__MODE_READ | __MODE_EOF | __MODE_ERR)) != __MODE_READ) {
      __thr_safe_unlock(fp);
      return EOF;
   }

   /* Nothing in the buffer - fill it up */
   if (fp->bufpos >= fp->bufread)
   {
      fp->bufpos = fp->bufread = fp->bufstart;
      ch = __fread(fp->bufpos, 1, fp->bufend - fp->bufstart, fp);
      if (ch == 0) {
         __thr_safe_unlock(fp);
         return EOF;
      }

      fp->bufread += ch;
      fp->mode |= __MODE_READING;
      fp->mode &= ~__MODE_UNGOT;
   }
   ch = *(fp->bufpos++);

#if __MODE_IOTRAN
   /* In MSDOS translation mode; WARN: Doesn't work with UNIX macro */
   if (ch == '\r' && (fp->mode & __MODE_IOTRAN))
      goto try_again;
#endif

   __thr_safe_unlock(fp);
   return ch;
}
Esempio n. 3
0
bool read_cert(char * buf, int len)
{
    FILE * pf;
    char   path[64];

    sprintf(path, "%s/cert_user.conf", "/topconf/topvp");

    if ((pf = fopen(path, "rb")) == NULL) {
        syslog(LOG_INFO, "open user cert failed");
        return false;
    }

    if (__fread(buf, len, 1, pf) < 0) {
        fclose(pf);
        syslog(LOG_INFO, "read user cert failed");
        return false;
    }
    fclose(pf);

    return true;
}
Esempio n. 4
0
#include <string.h>
#include "un-namespace.h"
#include "local.h"
#include "libc_private.h"

/*
 * MT-safe version
 */

size_t
fread(void * __restrict buf, size_t size, size_t count, FILE * __restrict fp)
{
	size_t ret;

	FLOCKFILE_CANCELSAFE(fp);
	ret = __fread(buf, size, count, fp);
	FUNLOCKFILE_CANCELSAFE();
	return (ret);
}

size_t
__fread(void * __restrict buf, size_t size, size_t count, FILE * __restrict fp)
{
	size_t resid;
	char *p;
	int r;
	size_t total;

	/*
	 * ANSI and SUSv2 require a return value of 0 if size or count are 0.
	 */