PosixStorage.cxx revision 7c478bd95313f5f23a4c958a745db2134aa03244
// Copyright (c) 1994, 1995 James Clark
// See the file COPYING for copying permission.
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef __GNUG__
#pragma implementation
#endif
#include "splib.h"
#include "PosixStorage.h"
#include "RewindStorageObject.h"
#include "StorageManager.h"
#include "DescriptorManager.h"
#include "MessageArg.h"
#include "ErrnoMessageArg.h"
#include "SearchResultMessageArg.h"
#include "Message.h"
#include "StringC.h"
#include "StringOf.h"
#include "CharsetInfo.h"
#include "CodingSystem.h"
#include "macros.h"
#include "PosixStorageMessages.h"
#include <stdio.h>
#include <ctype.h>
#ifdef SP_INCLUDE_IO_H
#include <io.h> // for open, fstat, lseek, read prototypes
#endif
#ifdef SP_INCLUDE_UNISTD_H
#include <unistd.h>
#endif
#ifdef SP_INCLUDE_OSFCN_H
#include <osfcn.h>
#endif
#include <fcntl.h>
#include <errno.h>
#include <stddef.h>
#ifndef S_ISREG
#ifndef S_IFREG
#endif
#ifndef S_IFMT
#endif
#endif /* not S_ISREG */
#ifndef O_BINARY
#define O_BINARY 0
#endif
#ifdef SP_WIDE_SYSTEM
#include <windows.h>
#endif
#ifdef SP_NAMESPACE
namespace SP_NAMESPACE {
#endif
#ifdef SP_WIDE_SYSTEM
typedef wchar_t FChar;
#else
typedef char FChar;
#endif
class PosixBaseStorageObject : public RewindStorageObject {
public:
size_t getBlockSize() const;
protected:
enum { defaultBlockSize = 8192 };
int fd_;
private:
};
{
}
{
return 0;
else
return 1;
}
{
eof_ = 0;
}
{
int ret;
do {
return ret;
}
public:
PosixStorageObject(int fd,
const StringC &,
void willNotRewind();
private:
const MessageType2 *suspendFailedMessage_;
int suspendErrno_;
};
#ifdef SP_WIDE_SYSTEM
}
return fd;
#else
#endif
}
const CharsetInfo *filenameCharset,
#ifndef SP_WIDE_SYSTEM
#endif
int maxFDs)
#ifndef SP_WIDE_SYSTEM
#endif
{
}
const char *PosixStorageManager::type() const
{
return type_;
}
{
}
#ifdef SP_POSIX_FILENAMES
#define FILENAME_TYPE_DEFINED
// FIXME should use idCharset.
{
}
{
return StringC();
}
{
result += '/';
return result;
}
Messenger &) const
{
if (fold)
if (c <= (unsigned char)-1)
}
return 1;
}
#endif /* SP_POSIX_FILENAMES */
#ifdef SP_MSDOS_FILENAMES
#define FILENAME_TYPE_DEFINED
{
if (s.size() == 0)
return 0;
}
{
return StringC();
}
{
result += '\\';
}
return result;
}
Messenger &) const
{
if (str[i] == '/')
str[i] = '\\';
return 1;
}
#endif /* SP_MSDOS_FILENAMES */
#ifdef SP_MAC_FILENAMES
// Colons separate directory names
// relative path-names start with a colon, or have no colons
// absolute path-names don't start with a colon and have at least one colon
#define FILENAME_TYPE_DEFINED
{
if (s.size() == 0)
return 0;
if (s[0] == ':')
return 0; // starts with a colon => relative
if (s[i] == ':')
return 1; // absolute
return 0; // no colons => relative
}
{
return StringC();
}
{
if (lastChar != ':')
result += ':';
}
if (base[0] == ':') {
}
return result;
}
Messenger &) const
{
}
else { // relative
}
if (str[i] == '/')
str[i] = ':';
return 1;
}
#endif /* SP_MAC_FILENAMES */
#ifndef FILENAME_TYPE_DEFINED
{
return 1;
}
{
return StringC();
}
{
return base;
}
Messenger &) const
{
return 1;
}
#endif /* not FILENAME_TYPE_DEFINED */
{
if (isAbsolute(specId))
return 1;
return 1;
}
return 0;
}
{
return 0;
}
if (absolute)
else if (i == 0)
else
#ifdef SP_WIDE_SYSTEM
#else
#endif
int fd;
do {
if (fd >= 0) {
return new PosixStorageObject(fd,
}
int savedErrno = errno;
return 0;
}
}
return 0;
}
suspended_(0),
{
}
{
if (fd_ >= 0) {
releaseD();
}
}
{
fd_ = -1;
return 0;
}
else
return 1;
}
{
return 1;
if (suspended_)
return 0;
long n;
do {
if (n > 0) {
return 1;
}
if (n < 0) {
releaseD();
fd_ = -1;
}
else {
eof_ = 1;
// n == 0, so end of file
if (!mayRewind_) {
releaseD();
fd_ = -1;
}
}
return 0;
}
void PosixStorageObject::willNotRewind()
{
releaseD();
fd_ = -1;
}
}
{
if (fd_ < 0 || suspended_)
return 0;
return 0;
}
}
fd_ = -1;
suspended_ = 1;
releaseD();
return 1;
}
{
if (suspendFailedMessage_) {
suspended_ = 0;
return;
}
acquireD();
// suspended_ must be 1 until after acquireD() is called,
// so that we don't try to suspend this one before it is resumed.
suspended_ = 0;
do {
if (fd_ < 0) {
releaseD();
return;
}
fd_ = -1;
releaseD();
}
}
#ifdef SP_STAT_BLKSIZE
{
long sz;
return defaultBlockSize;
return defaultBlockSize;
else
return sz;
}
#else /* not SP_STAT_BLKSIZE */
{
return defaultBlockSize;
}
#endif /* not SP_STAT_BLKSIZE */
const MessageType2 &msg,
int err)
{
}
class PosixFdStorageObject : public PosixBaseStorageObject {
public:
enum {
};
private:
int origFd_;
};
const CharsetInfo *idCharset)
{
}
{
return 0;
}
const StringC &,
{
int n = 0;
size_t i;
break;
break;
// Allow the division to be done at compile-time.
if (n > INT_MAX/10)
break;
n *= 10;
break;
n += digit;
}
return 0;
}
// Could check access mode with fcntl(n, F_GETFL).
return new PosixFdStorageObject(n, mayRewind);
}
{
}
const char *PosixFdStorageManager::type() const
{
return type_;
}
{
return 1;
return 0;
long n;
do {
if (n > 0) {
return 1;
}
if (n < 0) {
fd_ = -1;
}
else
eof_ = 1;
return 0;
}
{
return 0;
}
else
return 1;
}
#ifdef SP_NAMESPACE
}
#endif