mes/lib/tests/posix/50-open-read.c
Jan Nieuwenhuizen 89945751d9
hurd: Add open.
* include/fcntl.h (O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_APPEND,
O_TRUNC)[__GNU__]: Specialize for GNU.
* lib/gnu/dir-lookup.c: New file.
* lib/stdio/fopen.c (fopen): Use O_RDONLY.
* lib/tests/posix/50-open-read.c (main): Likewise.
* lib/tests/stdio/90-fseek.c (main): Likewise.
* include/gnu/syscall.h (SYS__dir_lookup): New value.
* lib/gnu/_open3.c: New file.
* build-aux/configure-lib.sh (libc_SOURCES): Build them.
2019-12-13 21:52:30 +01:00

58 lines
1.6 KiB
C

/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int
main (int argc, char const *argv[])
{
eputs ("test:getenv\n");
char file_name[PATH_MAX];
char *srcdir = getenv ("abs_top_srcdir");
if (! srcdir) // for running by hand
srcdir = ".";
eputs ("srcdir=");
eputs (srcdir);
eputs ("\n");
strcpy (file_name, srcdir);
strcpy (file_name + strlen (srcdir), "/lib/tests/posix/data/open-read");
eputs ("test open:");
eputs (file_name);
eputs ("\n");
int filedes = open (file_name, O_RDONLY, 0);
if (filedes <= 2)
return 1;
char buf[20];
int n = read (filedes, buf, sizeof (buf));
if (n != 5)
return 2;
if (strcmp (buf, "hello"))
return 3;
eputs ("test read: ");
eputs (buf);
eputs ("\n");
return 0;
}