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

int smbc_close ( int  fd  ) 

Close an open file handle.

Parameters:
fd The file handle to close
Returns:
0 on success, < 0 on error with errno set:
  • EBADF fd isn't a valid open file descriptor
  • EINVAL smbc_init() failed or has not been called
See also:
smbc_open(), smbc_creat()

Definition at line 848 of file libsmbclient.c.

References smbc_closedir().

Referenced by smbc_print_file().

{
      struct smbc_file *fe;
      struct smbc_server *srv;

      if (!smbc_initialized) {

            errno = EINVAL;
            return -1;

      }

      if (fd < smbc_start_fd || fd >= (smbc_start_fd + SMBC_MAX_FD)) {
   
            errno = EBADF;
            return -1;

      }

      fe = smbc_file_table[fd - smbc_start_fd];

      if (!fe) {

            errno = EBADF;
            return -1;

      }

      if (!fe->file) {

            return smbc_closedir(fd);

      }

      if (!cli_close(&fe->srv->cli, fe->cli_fd)) {
            DEBUG(3, ("cli_close failed on %s (%d). purging server.\n", 
                    fe->fname, fe->smbc_fd));
            /* Deallocate slot and remove the server 
             * from the server cache if unused */
            errno = smbc_errno(&fe->srv->cli);  
            srv = fe->srv;
            SAFE_FREE(fe->fname);
            SAFE_FREE(fe);
            smbc_file_table[fd - smbc_start_fd] = NULL;
            smbc_remove_unused_server(srv);
            return -1;
      }

      SAFE_FREE(fe->fname);
      SAFE_FREE(fe);
      smbc_file_table[fd - smbc_start_fd] = NULL;

      return 0;
}


Generated by  Doxygen 1.6.0   Back to index