Logo Search packages:      
Sourcecode: samba-doc-ja version File versions

int smbc_print_file ( const char *  fname,
const char *  printq 
)

Print a file given the name in fname. It would be a URL ...

Parameters:
fname The URL of a file on a remote SMB server that the caller wants printed
printq The URL of the print share to print the file to.
Returns:
0 on success, < 0 on error with errno set:
  • EINVAL fname or printq was NULL or smbc_init not not called. and errors returned by smbc_open

Definition at line 2405 of file libsmbclient.c.

References smbc_close(), smbc_open(), smbc_open_print_job(), smbc_read(), and smbc_write().

{
      int fid1, fid2, bytes, saverr, tot_bytes = 0;
      char buf[4096];

      if (!smbc_initialized) {

            errno = EINVAL;
            return -1;

      }

      if (!fname && !printq) {

            errno = EINVAL;
            return -1;

      }

      /* Try to open the file for reading ... */

      if ((fid1 = smbc_open(fname, O_RDONLY, 0666)) < 0) {
            
            DEBUG(3, ("Error, fname=%s, errno=%i\n", fname, errno));
            return -1;  /* smbc_open sets errno */
            
      }

      /* Now, try to open the printer file for writing */

      if ((fid2 = smbc_open_print_job(printq)) < 0) {

            saverr = errno;  /* Save errno */
            smbc_close(fid1);
            errno = saverr;
            return -1;

      }

      while ((bytes = smbc_read(fid1, buf, sizeof(buf))) > 0) {

            tot_bytes += bytes;

            if ((smbc_write(fid2, buf, bytes)) < 0) {

                  saverr = errno;
                  smbc_close(fid1);
                  smbc_close(fid2);
                  errno = saverr;

            }

      }

      saverr = errno;

      smbc_close(fid1);  /* We have to close these anyway */
      smbc_close(fid2);

      if (bytes < 0) {

            errno = saverr;
            return -1;

      }

      return tot_bytes;

}


Generated by  Doxygen 1.6.0   Back to index