home *** CD-ROM | disk | FTP | other *** search
- // testing of cheesy file descriptor type
- // object archiving.
- #import <stdio.h>
- #import <stdlib.h>
- #import <signal.h>
- #import <fcntl.h>
- #import <string.h>
- #import <sys/time.h>
- #import <RCString.h>
-
- int
- main(int c, char **v)
- {
- RCString *oString, *oString2;
-
- // cmd string1 string2 archive_file_name
- if (c != 4) {
- fprintf(stderr, "usage: %s string1 string2 archive_file_name\n", *v);
- exit(1);
- }
-
- oString = [RCString newFromString:v[1]];
- oString2 = [RCString newFromString:v[2]];
- if (oString && oString2) {
-
- char bvBuf[1024];
- int iArchiveFD = open(*(v + 3), O_RDWR|O_CREAT, 0666);
- if (iArchiveFD < 0) {
- perror("opening archive file");
- exit(2);
- }
-
- #ifdef NeXT
- printf("first RCString object in class \"%s\"\n", [oString name]);
- #endif
-
- printf("string 1: \"%s\"\n", [oString data]);
- printf("string 2: \"%s\"\n", [oString2 data]);
-
- [oString storeOn:iArchiveFD];
- if (lseek(iArchiveFD, 0, L_SET) >= 0) {
- // seeked back to start of file. Read in object.
- [oString2 readFrom:iArchiveFD];
- } else {
- // seek failed
- perror("seeking in archive file after object write");
- }
-
- printf("after de-archiving:\n");
- printf("string 1: \"%s\"\n", [oString data]);
- printf("string 2: \"%s\"\n", [oString2 data]);
-
- [oString free];
- [oString2 free];
- close(iArchiveFD);
- gets(bvBuf); // pause for check of file, etc.
- } else {
- fprintf(stderr, "newFromString: failure\n");
- return(1);
- }
- return(0);
- }
-