" -*- Smalltalk -*- " String readFromFileNamed: path ifError: errorBlock [ | cPath | self := self _clone. cPath := path _cString. { struct t_String *this= (struct t_String *)self; char *path= (char *)v_cPath; int fd= open(path, O_RDONLY); if (fd >= 0) { int position= 0; int remaining= 0; struct stat sb; fstat(fd, &sb); remaining= sb.st_size; this->_elements= (oop)_newBytes(remaining); while (remaining) { int count= read(fd, (char *)this->_elements + position, remaining); if (count < 1) break; position += count; remaining -= count; } close(fd); if (!remaining) { this->size= _integerObject(position); return self; } } }. ^errorBlock value ] String readFromFileNamed: path [ ^self readFromFileNamed: path ifError: [self error: path, ': ', Smalltalk osErrorString] ] String writeToFileNamed: path ifError: errorBlock [ | cPath | cPath := path _cString. { struct t_String *this= (struct t_String *)self; char *path= (char *)v_cPath; int fd= open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd >= 0) { int position= 0; int remaining= _integerValue(this->size); while (remaining) { int count= write(fd, (char *)this->_elements + position, remaining); if (count < 1) break; position += count; remaining -= count; } close(fd); if (!remaining) return self; } }. ^errorBlock value ] String writeToFileNamed: path [ ^self writeToFileNamed: path ifError: [self error: path, ': ', Smalltalk osErrorString] ]