Libpq coding assistance - Mailing list pgsql-general

From Scott Holmes
Subject Libpq coding assistance
Date
Msg-id 1004903734.17832.12.camel@scotts
Whole thread Raw
Responses Is there an internal timestamp on a table when it was created?
List pgsql-general
I am in need of some assistance in coding a c module using libpq on a
windows platform.  Specifically, I need some help with providing the
input buffer for lo_write.  The code sample provided in the
documentation contains this snippet:
------------

  lobj_fd = lo_open(conn, lobjId, INV_WRITE);

  while ((nbytes = read(fd, buffer,BUFSIZE)) > 0)
    {
      tmp = lo_write(conn, lobj_fd, buffer, nbytes);
      if (tmp < nbytes)
        fprintf(stderr, "error while reading large object\n");
    }

  (void) CloseHandle(fd);
  (void) lo_close(conn, lobj_fd);
------------

I need to change the read() statement to use ReadFile, thus:

------------
  lobj_fd = lo_open(conn, lobjId, INV_WRITE);

  while (ReadFile(fd, buffer, BUFSIZE, &nbytes, NULL)!=EOF )
    {
      tmp = lo_write(conn, lobj_fd, buffer, nbytes);
      if (tmp < nbytes)
        fprintf(stderr, "error while reading large object\n");
    }

  (void) lo_close(conn, lobj_fd);
  (void) CloseHandle(fd);
--------------

This, of course, doesn't work.  The program is reported as no longer responding.
An infinite loop I suspect. If anyone is doing this or knows how to code it,
I would be grateful.


--
---------------------------------------------------------------------
Scott Holmes                   http://pages.sbcglobal.net/scottholmes
                               scottholmes@sbcglobal.net

  Independent Programmer/Analyst                  Passport 4GL
  PHP HTML Composer                PostgreSQL     Informix 4GL, SQL
---------------------------------------------------------------------
      There are more things in heaven and earth, Horatio,
             than are dreamt of in your philosophy
---------------------------------------------------------------------


pgsql-general by date:

Previous
From: Jakub Ouhrabka
Date:
Subject: foreign keys and deadlock
Next
From: "Command Prompt, Inc."
Date:
Subject: Re: One more question about intervals