head	1.6;
access;
symbols
	REL2_0B:1.1.1.1.0.4
	REL2_0:1.1.1.1
	Release_2_0_0:1.1.1.1
	Release_1_0_3:1.1.1.1.0.2
	Release_2_0:1.1.1.1
	Release_1_0_2:1.1.1.1
	PG95-1_01:1.1.1.1
	PG95_DIST:1.1.1;
locks; strict;
comment	@ * @;


1.6
date	98.03.01.04.51.11;	author scrappy;	state dead;
branches;
next	1.5;

1.5
date	98.01.07.21.07.03;	author momjian;	state Exp;
branches;
next	1.4;

1.4
date	98.01.05.03.35.52;	author momjian;	state Exp;
branches;
next	1.3;

1.3
date	97.09.08.02.41.09;	author momjian;	state Exp;
branches;
next	1.2;

1.2
date	97.09.07.05.04.34;	author momjian;	state Exp;
branches;
next	1.1;

1.1
date	96.07.09.06.22.34;	author scrappy;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	96.07.09.06.22.34;	author scrappy;	state Exp;
branches;
next	;


desc
@@


1.6
log
@Move around files before applying Darren's second patch
@
text
@/*-------------------------------------------------------------------------
 *
 * beard.c--
 *	  sample routines to use large objects
 *
 * Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
 *	  $Header: /usr/local/cvsroot/pgsql/src/tutorial/C-code/beard.c,v 1.5 1998/01/07 21:07:03 momjian Exp scrappy $
 *
 *-------------------------------------------------------------------------
 */

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;
}
@


1.5
log
@Goodbye ABORT.  Hello ERROR for all errors.
@
text
@d10 1
a10 1
 *	  $Header: /usr/local/cvsroot/pgsql/src/tutorial/C-code/beard.c,v 1.4 1998/01/05 03:35:52 momjian Exp $
@


1.4
log
@Change elog(WARN) to elog(ERROR) and elog(ABORT).
@
text
@d10 1
a10 1
 *	  $Header: /usr/local/cvsroot/pgsql/src/tutorial/C-code/beard.c,v 1.3 1997/09/08 02:41:09 momjian Exp $
d37 1
a37 1
		elog(ABORT, "Cannot access picture large object");
d40 1
a40 1
		elog(ABORT, "Picture large object corrupted");
d48 1
a48 1
		elog(ABORT, "Cannot create new large object");
d51 1
a51 1
		elog(ABORT, "Cannot access beard large object");
d57 1
a57 1
			elog(ABORT, "error while writing large object");
@


1.3
log
@Another PGINDENT run that changes variable indenting and case label indenting.  Also static variable indenting.
@
text
@d10 1
a10 1
 *	  $Header: /usr/local/cvsroot/pgsql/src/tutorial/C-code/beard.c,v 1.2 1997/09/07 05:04:34 momjian Exp $
d37 1
a37 1
		elog(WARN, "Cannot access picture large object");
d40 1
a40 1
		elog(WARN, "Picture large object corrupted");
d48 1
a48 1
		elog(WARN, "Cannot create new large object");
d51 1
a51 1
		elog(WARN, "Cannot access beard large object");
d57 1
a57 1
			elog(WARN, "error while writing large object");
@


1.2
log
@Massive commit to run PGINDENT on all *.c and *.h files.
@
text
@d10 1
a10 1
 *	  $Header: /usr/local/cvsroot/pgsql/src/tutorial/C-code/beard.c,v 1.1.1.1 1996/07/09 06:22:34 scrappy Exp $
d17 2
a18 2
	int				size;
}				ImageHdr;
d29 6
a34 6
	Oid				beard;
	int				pic_fd,
					beard_fd;
	ImageHdr		ihdr;
	char			buf[BUFSIZE];
	int				cc;
@


1.1
log
@Initial revision
@
text
@d4 1
a4 1
 *    sample routines to use large objects
d10 1
a10 1
 *    $Header: /usr/local/cvsroot/postgres95/postgres95/src/tutorial/C-code/beard.c,v 1.1.1.1 1996/07/09 05:32:54 scrappy Exp $
d15 4
a18 3
typedef struct ImageHdr {
    int		size;
} ImageHdr;
d24 1
a24 1
 *   clips lower 1/3 of picture and return as large object
d29 30
a58 28
    Oid beard;
    int pic_fd, beard_fd;
    ImageHdr ihdr;
    char buf[BUFSIZE];
    int cc;

    if ((pic_fd = lo_open(picture, INV_READ)) == -1)
	elog(WARN, "Cannot access picture large object");

    if (lo_read(pic_fd, (char*)&ihdr, sizeof(ihdr)) != sizeof(ihdr))
	elog(WARN, "Picture large object corrupted");

    beardOffset = (ihdr.size / 3) * 2;

    /*
     * new large object
     */
    if ((beard = lo_creat(INV_MD)) == 0)  /* ?? is this right? */
	elog(WARN, "Cannot create new large object");

    if ((beard_fd = lo_open(beard, INV_WRITE)) == -1)
	elog(WARN, "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(WARN, "error while writing large object");
    }
d60 2
a61 2
    lo_close(pic_fd);
    lo_close(beard_fd);
d63 1
a63 1
    return beard;
a64 3



@


1.1.1.1
log
@Postgres95 1.01 Distribution - Virgin Sources
@
text
@@
