diff options
author | Marc G. Fournier <scrappy@hub.org> | 1998-03-01 04:51:16 +0000 |
---|---|---|
committer | Marc G. Fournier <scrappy@hub.org> | 1998-03-01 04:51:16 +0000 |
commit | f3f7712675abf9310859e4a1ccf6407dc3a3770e (patch) | |
tree | 1e6e5a87d4ff8cf7c14a3f1fc4019fa8d0c978d1 /src/tutorial/beard.c | |
parent | 56b3182241347aacb7b4c47519f009ffa2b57aa8 (diff) | |
download | postgresql-f3f7712675abf9310859e4a1ccf6407dc3a3770e.tar.gz |
Move around files before applying Darren's second patch
Diffstat (limited to 'src/tutorial/beard.c')
-rw-r--r-- | src/tutorial/beard.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/tutorial/beard.c b/src/tutorial/beard.c new file mode 100644 index 0000000000..9207f04d39 --- /dev/null +++ b/src/tutorial/beard.c @@ -0,0 +1,64 @@ +/*------------------------------------------------------------------------- + * + * beard.c-- + * sample routines to use large objects + * + * Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/tutorial/Attic/beard.c,v 1.1 1998/03/01 04:51:01 scrappy Exp $ + * + *------------------------------------------------------------------------- + */ + +typedef struct ImageHdr +{ + int size; +} ImageHdr; + +#define BUFSIZE 10 + +/* + * beard - + * clips lower 1/3 of picture and return as large object + */ +Oid +beard(Oid picture) +{ + Oid beard; + int pic_fd, + beard_fd; + ImageHdr ihdr; + char buf[BUFSIZE]; + int cc; + + if ((pic_fd = lo_open(picture, INV_READ)) == -1) + elog(ERROR, "Cannot access picture large object"); + + if (lo_read(pic_fd, (char *) &ihdr, sizeof(ihdr)) != sizeof(ihdr)) + elog(ERROR, "Picture large object corrupted"); + + beardOffset = (ihdr.size / 3) * 2; + + /* + * new large object + */ + if ((beard = lo_creat(INV_MD)) == 0) /* ?? is this right? */ + elog(ERROR, "Cannot create new large object"); + + if ((beard_fd = lo_open(beard, INV_WRITE)) == -1) + elog(ERROR, "Cannot access beard large object"); + + lo_lseek(pic_fd, beardOffset, SET_CUR); + while ((cc = lo_read(pic_fd, buf, BUFSIZE)) > 0) + { + if (lo_write(beard_fd, buf, cc) != cc) + elog(ERROR, "error while writing large object"); + } + + lo_close(pic_fd); + lo_close(beard_fd); + + return beard; +} |