home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Geek Gadgets 1
/
ADE-1.bin
/
ade-dist
/
kaffe-0.5p4-src.tgz
/
tar.out
/
contrib
/
kaffe
/
lib
/
native
/
java.io
/
FileOutputStream.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-09-28
|
2KB
|
92 lines
/*
* java.io.FileOutputStream.c
*
* Copyright (c) 1996 Systems Architecture Research Centre,
* City University, London, UK.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* Written by Tim Wilkinson <tim@sarc.city.ac.uk>, February 1996.
*/
#include "config.h"
#include <stdio.h>
#include <assert.h>
#if defined(HAVE_IO_H)
#include <io.h>
#endif
#include "defs.h"
#include "files.h"
#include "java.io.stubs/FileOutputStream.h"
#include "java.io.stubs/FileDescriptor.h"
#include "kthread.h"
/*
* Open a file for output.
*/
void
java_io_FileOutputStream_open(struct Hjava_io_FileOutputStream* fh, struct Hjava_lang_String* nm)
{
int fd;
char str[MAXPATHLEN];
javaString2CString(nm, str, sizeof(str));
fd = threadedOpen(str, O_WRONLY|O_CREAT|O_BINARY, 0666);
unhand(unhand(fh)->fd)->fd = fd;
if (fd < 0) {
SignalError(0, "java.io.IOException", SYS_ERROR);
}
}
/*
* Close a file.
*/
void
java_io_FileOutputStream_close(struct Hjava_io_FileOutputStream* fh)
{
int r;
if (unhand(unhand(fh)->fd)->fd >= 0) {
r = close(unhand(unhand(fh)->fd)->fd);
unhand(unhand(fh)->fd)->fd = -1;
if (r < 0) {
SignalError(0, "java.io.IOException", SYS_ERROR);
}
}
}
/*
* Write bytes to file.
*/
void
java_io_FileOutputStream_writeBytes(struct Hjava_io_FileOutputStream* fh, HArrayOfByte* byteArray, jint start, jint len)
{
int fd;
int r;
fd = unhand(unhand(fh)->fd)->fd;
r = threadedWrite(fd, &unhand(byteArray)->body[start], len);
if (r < 0) {
SignalError(0, "java.io.IOException", SYS_ERROR);
}
}
/*
* Write a byte to file.
*/
void
java_io_FileOutputStream_write(struct Hjava_io_FileOutputStream* fh, jint byte)
{
int fd;
int r;
unsigned char b = byte;
fd = unhand(unhand(fh)->fd)->fd;
r = threadedWrite(fd, &b, 1);
if (r < 0) {
SignalError(0, "java.io.IOException", SYS_ERROR);
}
}