This commit is contained in:
Jan Nieuwenhuizen 2019-10-24 09:08:47 +02:00
parent fcb694be6b
commit 44cd2f132f
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
7 changed files with 76 additions and 13 deletions

View File

@ -53,6 +53,8 @@
#define SYS_ioctl 0x36
// CONSTANT SYS_fsync 0x76
#define SYS_fsync 0x76
// CONSTANT SYS_getcwd 0xb7
#define SYS_getcwd 0xb7
/* libc+tcc */
#define SYS_close 0x06
@ -62,7 +64,6 @@
#define SYS_rmdir 0x28
#define SYS_gettimeofday 0x4e
#define SYS_stat 0x6a
#define SYS_getcwd 0xb7
/* libc+gnu */

32
lib/m2/_getcwd.c Normal file
View File

@ -0,0 +1,32 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,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-mini.h>
#include <linux/syscall.h>
#include <syscall.h>
char *
_getcwd (char *buffer, int size)
{
int r = _sys_call2 (SYS_getcwd, buffer, size);
if (r >= 0)
return buffer;
return 0;
}

View File

@ -20,8 +20,8 @@
struct timespec
{
long tv_sec;
long tv_nsec;
int tv_sec;
int tv_nsec;
};
int clock_gettime (int clk_id, struct timespec *tp);

View File

@ -18,4 +18,20 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
char *getcwd (char *buffer, size_t size);
#include <mes/lib.h>
#include <limits.h>
#include <sys/types.h>
#include <mes/lib.h>
// CONSTANT PATH_MAX 1024
char *
getcwd (char *buffer, int size)
{
if (! __itoa_buf)
__itoa_buf = malloc (20);
char *buf = __itoa_buf;
if (buffer)
return _getcwd (buffer, size);
return _getcwd (buf, PATH_MAX);
}

View File

@ -21,7 +21,7 @@
#include <string.h>
int
memcmp (void *s1, void *s2, size_t size)
memcmp (void *s1, void *s2, int size)
{
if (size == 0)
return 0;

View File

@ -22,10 +22,10 @@
#include <string.h>
void *
memcpy (void *dest, void const *src, size_t n)
memcpy (void *dest, void *src, int n)
{
char *p = dest;
char const *q = src;
char *q = src;
while (n != 0)
{

View File

@ -1,4 +1,4 @@
/* -*-comment-start: "//";comment-end:""-*-
/* -*-comment-start: "
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
@ -23,15 +23,29 @@
char *
strcpy (char *dest, char *src)
{
/* eputs ("\nstrcpy: src="); */
/* eputs (src); */
/* eputs ("\n"); */
char *p = dest;
char *orig = dest;
while (src[0] != 0)
/* eputs ("dest="); */
/* eputs (dest); */
/* eputs ("\n"); */
/* eputs ("c:" ); */
while (0 != src[0])
{
p[0] = src[0];
p + p + 1;
/* eputc (src[0]); */
/* eputs (" "); */
dest[0] = src[0];
dest = dest + 1;
src = src + 1;
}
p[0] = 0;
dest[0] = 0;
/* eputs ("\n => orig="); */
/* eputs (orig); */
/* eputs ("\n"); */
return dest;
return p;
}