mirror of https://github.com/postgres/postgres
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.4 KiB
65 lines
1.4 KiB
|
30 years ago
|
/*-------------------------------------------------------------------------
|
||
|
|
*
|
||
|
|
* beard.c--
|
||
|
29 years ago
|
* sample routines to use large objects
|
||
|
30 years ago
|
*
|
||
|
|
* Copyright (c) 1994, Regents of the University of California
|
||
|
|
*
|
||
|
|
*
|
||
|
|
* IDENTIFICATION
|
||
|
28 years ago
|
* $Header: /cvsroot/pgsql/src/tutorial/Attic/beard.c,v 1.1 1998/03/01 04:51:01 scrappy Exp $
|
||
|
30 years ago
|
*
|
||
|
|
*-------------------------------------------------------------------------
|
||
|
|
*/
|
||
|
|
|
||
|
29 years ago
|
typedef struct ImageHdr
|
||
|
|
{
|
||
|
29 years ago
|
int size;
|
||
|
|
} ImageHdr;
|
||
|
30 years ago
|
|
||
|
|
#define BUFSIZE 10
|
||
|
|
|
||
|
|
/*
|
||
|
|
* beard -
|
||
|
29 years ago
|
* clips lower 1/3 of picture and return as large object
|
||
|
30 years ago
|
*/
|
||
|
|
Oid
|
||
|
|
beard(Oid picture)
|
||
|
|
{
|
||
|
29 years ago
|
Oid beard;
|
||
|
|
int pic_fd,
|
||
|
|
beard_fd;
|
||
|
|
ImageHdr ihdr;
|
||
|
|
char buf[BUFSIZE];
|
||
|
|
int cc;
|
||
|
30 years ago
|
|
||
|
29 years ago
|
if ((pic_fd = lo_open(picture, INV_READ)) == -1)
|
||
|
28 years ago
|
elog(ERROR, "Cannot access picture large object");
|
||
|
30 years ago
|
|
||
|
29 years ago
|
if (lo_read(pic_fd, (char *) &ihdr, sizeof(ihdr)) != sizeof(ihdr))
|
||
|
28 years ago
|
elog(ERROR, "Picture large object corrupted");
|
||
|
30 years ago
|
|
||
|
29 years ago
|
beardOffset = (ihdr.size / 3) * 2;
|
||
|
30 years ago
|
|
||
|
29 years ago
|
/*
|
||
|
|
* new large object
|
||
|
|
*/
|
||
|
|
if ((beard = lo_creat(INV_MD)) == 0) /* ?? is this right? */
|
||
|
28 years ago
|
elog(ERROR, "Cannot create new large object");
|
||
|
30 years ago
|
|
||
|
29 years ago
|
if ((beard_fd = lo_open(beard, INV_WRITE)) == -1)
|
||
|
28 years ago
|
elog(ERROR, "Cannot access beard large object");
|
||
|
30 years ago
|
|
||
|
29 years ago
|
lo_lseek(pic_fd, beardOffset, SET_CUR);
|
||
|
|
while ((cc = lo_read(pic_fd, buf, BUFSIZE)) > 0)
|
||
|
|
{
|
||
|
|
if (lo_write(beard_fd, buf, cc) != cc)
|
||
|
28 years ago
|
elog(ERROR, "error while writing large object");
|
||
|
29 years ago
|
}
|
||
|
30 years ago
|
|
||
|
29 years ago
|
lo_close(pic_fd);
|
||
|
|
lo_close(beard_fd);
|
||
|
30 years ago
|
|
||
|
29 years ago
|
return beard;
|
||
|
30 years ago
|
}
|