Skip to content

Commit

Permalink
add tmpfile() and tmpnam() since they are nto included with PS5 libs
Browse files Browse the repository at this point in the history
  • Loading branch information
john-tornblom committed May 10, 2024
1 parent c49a97e commit f6bec3d
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ MAKE ?= make
DESTDIR ?= /opt/ps5-payload-sdk

TOPTARGETS := all clean install
SUBDIRS := crt sce_stubs locale libm include host
SUBDIRS := crt sce_stubs libc libm include host

$(TOPTARGETS): $(SUBDIRS)

Expand Down
2 changes: 1 addition & 1 deletion host/bin/prospero-clang
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SCRIPT_DIR="$(dirname "${SCRIPT_PATH}")"

PS5_PAYLOAD_SDK="$(realpath "${SCRIPT_DIR}/..")"

LIBS="-lSceLibcInternal -lScePosixForWebKit -lc_locale"
LIBS="-lSceLibcInternal -lScePosixForWebKit -lc"
for ARG in "$@"; do
if [[ "$ARG" == "-c" || "$ARG" == "-nostdlibc" ]]; then
LIBS=""
Expand Down
2 changes: 1 addition & 1 deletion host/bin/prospero-clang++
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SCRIPT_DIR="$(dirname "${SCRIPT_PATH}")"

PS5_PAYLOAD_SDK="$(realpath "${SCRIPT_DIR}/..")"

LIBS_C="-lSceLibcInternal -lScePosixForWebKit -lc_locale"
LIBS_C="-lSceLibcInternal -lScePosixForWebKit -lc"
LIBS_CXX="-lc++ -lc++abi -lunwind"
for ARG in "$@"; do
if [[ "$ARG" == "-c" || "$ARG" == "-nostdlib" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion locale/Makefile → libc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ CFLAGS += -nobuiltininc -isystem ../include/freebsd
SRCS := $(wildcard *.c)
OBJS := $(SRCS:.c=.o)

ARCHIVE := libc_locale.a
ARCHIVE := libc.a

all: $(ARCHIVE)

Expand Down
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions libc/tmpfile.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* Copyright (C) 2024 John Törnblom
This program 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, 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>. */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>


FILE*
tmpfile(void) {
char s[] = "/user/temp/tmpfile_XXXXXX";
FILE* f;
int fd;

if((fd=mkstemp(s)) < 0) {
return 0;
}

if(!(f=fdopen(fd, "rw+b"))) {
close(fd);
}

return f;
}
39 changes: 39 additions & 0 deletions libc/tmpnam.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Copyright (C) 2024 John Törnblom
This program 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, 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>. */

#include <string.h>
#include <unistd.h>


char*
tmpnam(char* s) {
char tmpl[] = "/user/temp/tmpfile_XXXXXX";
int fd;

if((fd=mkstemp(tmpl)) < 0) {
return 0;
}

close(fd);
unlink(tmpl);

if(s) {
strcpy(s, tmpl);
return s;
}

return strdup(tmpl);
}
File renamed without changes.

0 comments on commit f6bec3d

Please sign in to comment.