mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
printf(3) now writes to fd 1.
This commit is contained in:
parent
e72d086a8f
commit
4890c306c4
7 changed files with 42 additions and 51 deletions
|
@ -43,9 +43,15 @@
|
||||||
#define __POSIX_OBSOLETE 200112L
|
#define __POSIX_OBSOLETE 200112L
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sortix/bits.h>
|
/* Whether sortix-specific extensions to the C library are available. */
|
||||||
|
#ifndef SORTIX_NO_EXTENSIONS
|
||||||
|
#define SORTIX_EXTENSIONS
|
||||||
|
#endif
|
||||||
|
|
||||||
// Don't provide things from standard headers that is not implemented in libmaxsi/sortix.
|
/* Don't provide things from standard headers that is not implemented. */
|
||||||
#define SORTIX_UNIMPLEMENTED
|
#define SORTIX_UNIMPLEMENTED
|
||||||
|
|
||||||
|
#include <sortix/bits.h>
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
more details.
|
more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with LibMaxsi. If not, see <http:/*www.gnu.org/licenses/>.
|
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
unistd.h
|
unistd.h
|
||||||
The <unistd.h> header defines miscellaneous symbolic constants and types,
|
The <unistd.h> header defines miscellaneous symbolic constants and types,
|
||||||
|
@ -170,6 +170,9 @@ int usleep(useconds_t useconds);
|
||||||
#endif
|
#endif
|
||||||
int unlink(const char*);
|
int unlink(const char*);
|
||||||
ssize_t write(int, const void*, size_t);
|
ssize_t write(int, const void*, size_t);
|
||||||
|
#ifdef SORTIX_EXTENSIONS
|
||||||
|
int writeall(int fd, const void* buffer, size_t len);
|
||||||
|
#endif
|
||||||
|
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,9 @@
|
||||||
#include "syscall.h"
|
#include "syscall.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
#include "format.h"
|
#include "format.h"
|
||||||
|
#include "string.h"
|
||||||
#include <sys/readdirents.h>
|
#include <sys/readdirents.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
namespace Maxsi
|
namespace Maxsi
|
||||||
{
|
{
|
||||||
|
@ -42,14 +44,17 @@ namespace Maxsi
|
||||||
DEFN_SYSCALL2(char*, SysGetCWD, 26, char*, size_t);
|
DEFN_SYSCALL2(char*, SysGetCWD, 26, char*, size_t);
|
||||||
DEFN_SYSCALL1(int, SysUnlink, 27, const char*);
|
DEFN_SYSCALL1(int, SysUnlink, 27, const char*);
|
||||||
|
|
||||||
size_t Print(const char* Message)
|
size_t Print(const char* string)
|
||||||
{
|
{
|
||||||
return SysPrint(Message);
|
size_t stringlen = String::Length(string);
|
||||||
|
if ( writeall(1, string, stringlen) ) { return 0; }
|
||||||
|
return stringlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t PrintCallback(void* user, const char* string, size_t stringlen)
|
size_t PrintCallback(void* user, const char* string, size_t stringlen)
|
||||||
{
|
{
|
||||||
return SysPrint(string);
|
if ( writeall(1, string, stringlen) ) { return 0; }
|
||||||
|
return stringlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t PrintF(const char* format, ...)
|
size_t PrintF(const char* format, ...)
|
||||||
|
@ -81,6 +86,20 @@ namespace Maxsi
|
||||||
return SysWrite(fd, buf, count);
|
return SysWrite(fd, buf, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" int writeall(int fd, const void* buffer, size_t len)
|
||||||
|
{
|
||||||
|
const char* buf = (const char*) buffer;
|
||||||
|
while ( len )
|
||||||
|
{
|
||||||
|
ssize_t byteswritten = write(fd, buf, len);
|
||||||
|
if ( byteswritten < 0 ) { return (int) byteswritten; }
|
||||||
|
buf += byteswritten;
|
||||||
|
len -= byteswritten;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" int pipe(int pipefd[2])
|
extern "C" int pipe(int pipefd[2])
|
||||||
{
|
{
|
||||||
return SysPipe(pipefd);
|
return SysPipe(pipefd);
|
||||||
|
|
|
@ -5,20 +5,6 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <libmaxsi/sortix-keyboard.h>
|
#include <libmaxsi/sortix-keyboard.h>
|
||||||
|
|
||||||
bool writeall(int fd, const void* buffer, size_t len)
|
|
||||||
{
|
|
||||||
const char* buf = (const char*) buffer;
|
|
||||||
while ( len )
|
|
||||||
{
|
|
||||||
ssize_t byteswritten = write(fd, buf, len);
|
|
||||||
if ( byteswritten < 0 ) { return false; }
|
|
||||||
buf += byteswritten;
|
|
||||||
len -= byteswritten;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int cat(int argc, char* argv[])
|
int cat(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
@ -48,7 +34,7 @@ int cat(int argc, char* argv[])
|
||||||
result = 1;
|
result = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ( !writeall(outfd, buffer, bytesread) )
|
if ( writeall(outfd, buffer, bytesread) )
|
||||||
{
|
{
|
||||||
printf("%s: /dev/tty: %s\n", argv[0], strerror(errno));
|
printf("%s: /dev/tty: %s\n", argv[0], strerror(errno));
|
||||||
result = 1;
|
result = 1;
|
||||||
|
|
16
utils/cp.cpp
16
utils/cp.cpp
|
@ -4,20 +4,6 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
bool writeall(int fd, const void* buffer, size_t len)
|
|
||||||
{
|
|
||||||
const char* buf = (const char*) buffer;
|
|
||||||
while ( len )
|
|
||||||
{
|
|
||||||
ssize_t byteswritten = write(fd, buf, len);
|
|
||||||
if ( byteswritten < 0 ) { return false; }
|
|
||||||
buf += byteswritten;
|
|
||||||
len -= byteswritten;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* basename(const char* path)
|
const char* basename(const char* path)
|
||||||
{
|
{
|
||||||
size_t len = strlen(path);
|
size_t len = strlen(path);
|
||||||
|
@ -62,6 +48,6 @@ int main(int argc, char* argv[])
|
||||||
ssize_t bytesread = read(fromfd, buffer, BUFFER_SIZE);
|
ssize_t bytesread = read(fromfd, buffer, BUFFER_SIZE);
|
||||||
if ( bytesread < 0 ) { printf("%s: %s: %s\n", argv[0], frompath, strerror(errno)); return 1; }
|
if ( bytesread < 0 ) { printf("%s: %s: %s\n", argv[0], frompath, strerror(errno)); return 1; }
|
||||||
if ( bytesread == 0 ) { return 0; }
|
if ( bytesread == 0 ) { return 0; }
|
||||||
if ( !writeall(tofd, buffer, bytesread) ) { printf("%s: %s: %s\n", argv[0], topath, strerror(errno)); return 1; }
|
if ( writeall(tofd, buffer, bytesread) ) { printf("%s: %s: %s\n", argv[0], topath, strerror(errno)); return 1; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,20 +192,6 @@ unsigned confirmquit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool writeall(int fd, const void* buffer, size_t len)
|
|
||||||
{
|
|
||||||
const char* buf = (const char*) buffer;
|
|
||||||
while ( len )
|
|
||||||
{
|
|
||||||
ssize_t byteswritten = write(fd, buf, len);
|
|
||||||
if ( byteswritten < 0 ) { return false; }
|
|
||||||
buf += byteswritten;
|
|
||||||
len -= byteswritten;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool savetofile(const char* path)
|
bool savetofile(const char* path)
|
||||||
{
|
{
|
||||||
int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0777);
|
int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0777);
|
||||||
|
@ -215,7 +201,7 @@ bool savetofile(const char* path)
|
||||||
{
|
{
|
||||||
size_t len = strlen(buffers[y]);
|
size_t len = strlen(buffers[y]);
|
||||||
buffers[y][len] = '\n';
|
buffers[y][len] = '\n';
|
||||||
bool result = writeall(fd, buffers[y], len+1);
|
bool result = !writeall(fd, buffers[y], len+1);
|
||||||
buffers[y][len] = 0;
|
buffers[y][len] = 0;
|
||||||
if ( !result ) { printf("%s: %s\n", path, strerror(errno)); close(fd); return false; }
|
if ( !result ) { printf("%s: %s\n", path, strerror(errno)); close(fd); return false; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <libmaxsi/platform.h>
|
#include <libmaxsi/platform.h>
|
||||||
#include <libmaxsi/process.h>
|
#include <libmaxsi/process.h>
|
||||||
#include <libmaxsi/thread.h>
|
#include <libmaxsi/thread.h>
|
||||||
|
@ -27,6 +28,10 @@ int child()
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
if ( open("/dev/tty", O_RDONLY) != 0 ) { return 2; }
|
||||||
|
if ( open("/dev/tty", O_WRONLY | O_APPEND) != 1 ) { return 2; }
|
||||||
|
if ( open("/dev/tty", O_WRONLY | O_APPEND) != 2 ) { return 2; }
|
||||||
|
|
||||||
// Reset the terminal's color and the rest of it.
|
// Reset the terminal's color and the rest of it.
|
||||||
printf("\r\e[m\e[J");
|
printf("\r\e[m\e[J");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue