Skip to content
Snippets Groups Projects
Commit d7cfcf79 authored by Alexandru-Daniel BARBU's avatar Alexandru-Daniel BARBU
Browse files

Merge branch 'solution' into 'master'

IO functions have been made, also i have done sleep and nanosleep with some problem to nanosleep.

See merge request alexandru.barbu2809/assignment-mini-libc!3
parents 6c74eecd 67ed6e0f
No related branches found
No related tags found
No related merge requests found
Pipeline #75338 passed
......@@ -7,11 +7,11 @@ CFLAGS += -g -O0
.PHONY: all clean pack
SRCS = syscall.c \
process/exit.c \
process/exit.c process/nanosleep.c process/sleep.c\
mm/malloc.c mm/mmap.c mm/mem_list.c \
string/string.c \
stat/fstatat.c stat/fstat.c stat/stat.c \
io/open.c io/close.c io/read_write.c \
io/open.c io/close.c io/read_write.c io/puts.c\
io/lseek.c io/truncate.c io/ftruncate.c \
errno.c \
crt/__libc_start_main.c
......
......@@ -4,8 +4,17 @@
#include <internal/syscall.h>
#include <errno.h>
#define SYSTEM_LSEEK 8
off_t lseek(int fd, off_t offset, int whence)
{
/* TODO: Implement lseek(). */
int result = syscall(SYSTEM_LSEEK, fd, offset, whence);
if (result >= 0)
{
return result;
}
errno = -result;
return -1;
}
// SPDX-License-Identifier: BSD-3-Clause
#include <unistd.h>
#include <internal/syscall.h>
#include <stdarg.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#define STDOUT 1
int puts(const char *s)
{
/* TODO: Implement puts() without a :)) */
int check1 = write(STDOUT, s, strlen(s));
if (check1 >= 0)
{
int check2 = write(STDOUT, "\n\0", 2);
if (check2 >= 0)
{
return 0;
}
}
return -1;
}
......@@ -4,8 +4,17 @@
#include <internal/syscall.h>
#include <errno.h>
#define SYSTEM_TRUNCATE 76
int truncate(const char *path, off_t length)
{
/* TODO: Implement truncate(). */
int result = syscall(SYSTEM_TRUNCATE, path, length);
if (result >= 0)
{
return 0;
}
errno = -result;
return -1;
}
// SPDX-License-Identifier: BSD-3-Clause
#include <internal/syscall.h>
#include <stdlib.h>
#include "time.h"
#include <errno.h>
#define SYSCALL_NANOSLEEP 35
int nanosleep(const struct timespec *duration, struct timespec *rem)
{
int result = syscall(SYSCALL_NANOSLEEP, duration, rem);
if (result >= 0)
{
return 0;
}
errno = -result;
return -1;
}
// SPDX-License-Identifier: BSD-3-Clause
#include <internal/syscall.h>
#include <stdlib.h>
#include "time.h"
unsigned int sleep(unsigned int seconds)
{
struct timespec sec, remainder;
sec.tv_sec = seconds;
sec.tv_nsec = 0;
if (nanosleep(&sec, &remainder) != 1)
{
return remainder.tv_sec;
}
return 0;
}
#ifndef __TIME_H__
#define __TIME_H__ 1
struct timespec {
long long tv_sec;
long tv_nsec;
};
int nanosleep(const struct timespec *duration, struct timespec *rem);
unsigned int sleep(unsigned int seconds);
#endif
......@@ -4,8 +4,17 @@
#include <internal/syscall.h>
#include <errno.h>
#define SYSCALL_FSTAT 5
int fstat(int fd, struct stat *st)
{
/* TODO: Implement fstat(). */
int result = syscall(SYSCALL_FSTAT, fd, st);
if (result >= 0)
{
return 0;
}
errno = -result;
return -1;
}
......@@ -40,14 +40,24 @@ struct statx {
uint64_t spare[14];
};
#define SYSCALL_NEW_FSTATAT 262
int fstatat_statx(int fd, const char *restrict path, struct stat *restrict st, int flag)
{
/* TODO: Implement fstatat_statx(). Use statx and makedev above. */
// int result = syscall(SYSCALL_NEW_FSTATAT, fd, path, st, flag);
// if (result >= 0)
// {
// return 0;
// }
// errno = -result;
return -1;
}
int fstatat(int fd, const char *restrict path, struct stat *restrict st, int flag)
{
/* TODO: Implement fstatat(). Use fstatat_statx(). */
return -1;
}
......@@ -5,8 +5,17 @@
#include <fcntl.h>
#include <errno.h>
#define SYSCALL_STAT 4
int stat(const char *restrict path, struct stat *restrict buf)
{
/* TODO: Implement stat(). */
int result = syscall(SYSCALL_STAT, path, buf);
if (result >= 0)
{
return 0;
}
errno = -result;
return -1;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment