summaryrefslogtreecommitdiff
path: root/cpu/sysdeps/unix/sysv/linux/i386/sys-read.c
blob: 7e139755e04e22a5f89b3bff757b1e8883b05e8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/***************************************************************
  SYS-READ.C

       This file contains Linux/i386/ILP32 implementation of
       __cpu_sys_read().

       PART OF : CPU - library .

       USAGE   : Internal only .

       Copyright (C) 2026  by Andrew V.Kosteltsev.
       All Rights Reserved.
 ***************************************************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <errno.h>
#include <stdint.h>
#include <unistd.h>

#include <libmcpu.h>
#include <cpu-sysdeps.h>

__mpu_int64_t
__cpu_sys_read( int fd, void *buf, __mpu_uint64_t count )
{
  ssize_t ret;

  if( count > (__mpu_uint64_t)SIZE_MAX ) return( -(__mpu_int64_t)__MCPU_EINVAL );
  ret = read( fd, buf, (size_t)count );
  if( ret < 0 ) return( -(__mpu_int64_t)__cpu_errno_from_host( errno ) );
  return( (__mpu_int64_t)ret );
}