/*
 * unistd.h
 *
 * Copyright (C) 2017 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _UNISTD_H_
#define _UNISTD_H_

#include <stddef.h>
#include <stdint.h>

#define PATH_MAX 16384

#define STDIN_FILENO  0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2

#define O_RDONLY   0
#define O_WRONLY   1
#define O_RDWR     2
#define O_CREAT    (1 << 6)
#define O_EXCL     (1 << 7)
#define O_TRUNC    (1 << 9)
#define O_APPEND   (1 << 10)
#define O_NONBLOCK (1 << 11)

#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2

typedef uint16_t mode_t;

typedef ptrdiff_t off_t;
typedef ptrdiff_t ssize_t;

char *getcwd(char *buf, size_t size);
char *getwd(char *buf);
char *get_current_dir_name(void);
int fchdir(int fd);
int chdir(const char *path);

#ifndef __DONT_DEFINE_OPEN__
int open(const char *pathname, int flags, ...);
#endif

int creat(const char *pathname, mode_t mode);
int close(int fd);
ssize_t read(int fd, void *buf, size_t count);
ssize_t write(int fd, const void *buf, size_t count);
off_t lseek(int fd, off_t offset, int whence);

#endif
