Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/net/netinet/in.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT

#pragma once

/*
* Provide the BSD netinet/in.h include path expected by Unix-oriented
* third-party libraries while reusing nxdk's lwIP socket compatibility layer.
*/

#include <sys/socket.h>
10 changes: 10 additions & 0 deletions lib/net/netinet/tcp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT

#pragma once

/*
* Provide the BSD netinet/tcp.h include path expected by Unix-oriented
* third-party libraries while reusing nxdk's lwIP socket compatibility layer.
*/

#include <sys/socket.h>
37 changes: 37 additions & 0 deletions lib/xboxrt/libc_extensions/conio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MIT

#pragma once

/*
* Provide the tiny conio.h subset that some cross-built utility code expects.
* The Xbox runtime does not provide a console keyboard in these call sites, so
* the helpers intentionally report no pending input.
*/

#ifdef __cplusplus
extern "C" {
#endif

static inline int _kbhit(void)
{
return 0;
}

static inline int _getch(void)
{
return -1;
}

static inline int kbhit(void)
{
return _kbhit();
}

static inline int getch(void)
{
return _getch();
}

#ifdef __cplusplus
}
#endif
40 changes: 40 additions & 0 deletions lib/xboxrt/libc_extensions/dirent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: MIT

#pragma once

/*
* Provide a minimal dirent surface for code that is compiled as part of a
* third-party build but does not enumerate Xbox directories at runtime.
*/

#ifdef __cplusplus
extern "C" {
#endif

struct dirent {
char d_name[256];
};

typedef struct nxdk_dir_stub DIR;

static inline DIR *opendir(const char *path)
{
(void) path;
return 0;
}

static inline int closedir(DIR *directory)
{
(void) directory;
return -1;
}

static inline struct dirent *readdir(DIR *directory)
{
(void) directory;
return 0;
}

#ifdef __cplusplus
}
#endif
4 changes: 4 additions & 0 deletions lib/xboxrt/libc_extensions/errno_ext_.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@
#define _PDCLIB_ERRNO_T_DEFINED _PDCLIB_ERRNO_T_DEFINED
typedef int errno_t;
#endif

#ifndef EHOSTDOWN
#define EHOSTDOWN EHOSTUNREACH
#endif
41 changes: 41 additions & 0 deletions lib/xboxrt/libc_extensions/fcntl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: MIT

#pragma once

/*
* Provide the subset of fcntl.h constants that nxdk consumers currently need.
*
* Some libraries only need this header to exist, while others also depend on
* the open mode constants below.
*/

#ifndef O_RDONLY
#define O_RDONLY 0x0000
#endif
#ifndef O_WRONLY
#define O_WRONLY 0x0001
#endif
#ifndef O_RDWR
#define O_RDWR 0x0002
#endif
#ifndef O_ACCMODE
#define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
#endif
#ifndef O_CREAT
#define O_CREAT 0x0100
#endif
#ifndef O_EXCL
#define O_EXCL 0x0200
#endif
#ifndef O_TRUNC
#define O_TRUNC 0x0400
#endif
#ifndef O_APPEND
#define O_APPEND 0x0800
#endif
#ifndef O_BINARY
#define O_BINARY 0x0000
#endif
#ifndef O_TEXT
#define O_TEXT 0x0000
#endif
10 changes: 10 additions & 0 deletions lib/xboxrt/libc_extensions/memory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT

#pragma once

/*
* Older third-party sources may still include memory.h for the standard string
* and memory routines. Route that legacy include to string.h.
*/

#include <string.h>
10 changes: 10 additions & 0 deletions lib/xboxrt/libc_extensions/poll.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT

#pragma once

/*
* Provide the POSIX poll.h include path expected by Unix-oriented third-party
* libraries while reusing nxdk's socket compatibility layer.
*/

#include <sys/socket.h>
31 changes: 31 additions & 0 deletions lib/xboxrt/libc_extensions/string_ext_.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,37 @@ char *strdup (const char *s)
return new_s;
}

char *strtok_r(char *str, const char *delim, char **saveptr)
{
char *token;
char *end;

if (str != NULL) {
*saveptr = str;
}

if (*saveptr == NULL) {
return NULL;
}

*saveptr += strspn(*saveptr, delim);
if (**saveptr == '\0') {
*saveptr = NULL;
return NULL;
}

token = *saveptr;
end = token + strcspn(token, delim);
if (*end == '\0') {
*saveptr = NULL;
} else {
*end = '\0';
*saveptr = end + 1;
}

return token;
}

int _strnicmp (const char *s1, const char *s2, size_t n)
{
assert(s1);
Expand Down
1 change: 1 addition & 0 deletions lib/xboxrt/libc_extensions/string_ext_.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern "C" {
#endif

char *strdup (const char *s);
char *strtok_r(char *str, const char *delim, char **saveptr);

static char *_strdup (const char *s)
{
Expand Down
10 changes: 10 additions & 0 deletions lib/xboxrt/libc_extensions/sys/ioctl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT

#pragma once

/*
* Provide the POSIX sys/ioctl.h include path expected by Unix-oriented
* third-party libraries while reusing nxdk's socket compatibility layer.
*/

#include <sys/socket.h>
38 changes: 38 additions & 0 deletions lib/xboxrt/libc_extensions/sys/resource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: MIT

#pragma once

/*
* Provide the small sys/resource.h subset required by libraries that probe for
* process usage statistics during build-time utility code paths.
*/

#include <stddef.h>
#include <sys/time.h>

#ifdef __cplusplus
extern "C" {
#endif

#define RUSAGE_SELF 0

struct rusage {
struct timeval ru_utime;
struct timeval ru_stime;
};

static inline int getrusage(int who, struct rusage *usage)
{
(void) who;
if (usage != NULL) {
usage->ru_utime.tv_sec = 0;
usage->ru_utime.tv_usec = 0;
usage->ru_stime.tv_sec = 0;
usage->ru_stime.tv_usec = 0;
}
return -1;
}

#ifdef __cplusplus
}
#endif
10 changes: 10 additions & 0 deletions lib/xboxrt/libc_extensions/sys/select.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT

#pragma once

/*
* Provide the POSIX sys/select.h include path expected by Unix-oriented
* third-party libraries while reusing nxdk's socket compatibility layer.
*/

#include <sys/socket.h>
77 changes: 77 additions & 0 deletions lib/xboxrt/libc_extensions/sys/stat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// SPDX-License-Identifier: MIT

#pragma once

/*
* Provide the limited sys/stat.h surface currently needed by nxdk consumers.
*
* This keeps the declarations close to the rest of nxdk's libc extension layer
* while the underlying file metadata support remains intentionally small.
*/

#include <sys/types.h>
#include <time.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifndef NXDK_DEV_T_DEFINED
#define NXDK_DEV_T_DEFINED
typedef unsigned int dev_t;
#endif

#ifndef NXDK_INO_T_DEFINED
#define NXDK_INO_T_DEFINED
typedef unsigned int ino_t;
#endif

#ifndef NXDK_NLINK_T_DEFINED
#define NXDK_NLINK_T_DEFINED
typedef unsigned int nlink_t;
#endif

#ifndef S_IFMT
#define S_IFMT 0170000
#endif
#ifndef S_IFDIR
#define S_IFDIR 0040000
#endif
#ifndef S_IFCHR
#define S_IFCHR 0020000
#endif
#ifndef S_IFBLK
#define S_IFBLK 0060000
#endif
#ifndef S_IFREG
#define S_IFREG 0100000
#endif
#ifndef S_ISDIR
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
#endif
#ifndef S_ISREG
#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
#endif

struct stat {
dev_t st_dev;
mode_t st_mode;
ino_t st_ino;
nlink_t st_nlink;
uid_t st_uid;
gid_t st_gid;
dev_t st_rdev;
unsigned int st_size;
time_t st_atime;
time_t st_mtime;
time_t st_ctime;
};

int fstat(int fd, struct stat *status);
int stat(const char *path, struct stat *status);
int _fstat(int fd, struct stat *status);
int _stat(const char *path, struct stat *status);

#ifdef __cplusplus
}
#endif
Loading
Loading