G2A Many GEOs
SHARE
TWEET

Untitled

a guest Mar 31st, 2020 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "holberton.h"
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. #include <stdlib.h>
  7. /**
  8.  * read_textfile - function that print a binary
  9.  * @filename: name of file
  10.  * @letters: letters
  11.  * Return:
  12.  */
  13.  
  14. ssize_t read_textfile(const char *filename, size_t letters)
  15. {
  16.     int o, r, w, c;
  17.     char *d;
  18.  
  19.     d = malloc(sizeof(char) * letters);
  20.     if (d == NULL)
  21.         return (0);
  22.     o = open(filename, O_RDWR);
  23.     if (o == -1)
  24.     {
  25.         free(d);
  26.         return (0);
  27.     }
  28.     r = read(o, d, letters);
  29.     w = write(STDOUT_FILENO, d, (ssize_t)r);
  30.     if (w == -1)
  31.     {
  32.         free(d);
  33.         return (0);
  34.     }
  35.     if (r != w)
  36.         return (0);
  37.     free(d);
  38.     c = close(o);
  39.     if (c == -1)
  40.         return (0);
  41.     return (w);
  42. }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top