PageRenderTime 28ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/gecko_api/include/prio.h

http://firefox-mac-pdf.googlecode.com/
C Header | 2030 lines | 502 code | 181 blank | 1347 comment | 1 complexity | d9ed352c7cc66d1022bc8bfaa929dbb8 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is the Netscape Portable Runtime (NSPR).
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998-2000
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. /*
  38. * File: prio.h
  39. *
  40. * Description: PR i/o related stuff, such as file system access, file
  41. * i/o, socket i/o, etc.
  42. */
  43. #ifndef prio_h___
  44. #define prio_h___
  45. #include "prlong.h"
  46. #include "prtime.h"
  47. #include "prinrval.h"
  48. #include "prinet.h"
  49. PR_BEGIN_EXTERN_C
  50. /* Typedefs */
  51. typedef struct PRDir PRDir;
  52. typedef struct PRDirEntry PRDirEntry;
  53. #ifdef MOZ_UNICODE
  54. typedef struct PRDirUTF16 PRDirUTF16;
  55. typedef struct PRDirEntryUTF16 PRDirEntryUTF16;
  56. #endif /* MOZ_UNICODE */
  57. typedef struct PRFileDesc PRFileDesc;
  58. typedef struct PRFileInfo PRFileInfo;
  59. typedef struct PRFileInfo64 PRFileInfo64;
  60. typedef union PRNetAddr PRNetAddr;
  61. typedef struct PRIOMethods PRIOMethods;
  62. typedef struct PRPollDesc PRPollDesc;
  63. typedef struct PRFilePrivate PRFilePrivate;
  64. typedef struct PRSendFileData PRSendFileData;
  65. /*
  66. ***************************************************************************
  67. ** The file descriptor.
  68. ** This is the primary structure to represent any active open socket,
  69. ** whether it be a normal file or a network connection. Such objects
  70. ** are stackable (or layerable). Each layer may have its own set of
  71. ** method pointers and context private to that layer. All each layer
  72. ** knows about its neighbors is how to get to their method table.
  73. ***************************************************************************
  74. */
  75. typedef PRIntn PRDescIdentity; /* see: Layering file descriptors */
  76. struct PRFileDesc {
  77. const PRIOMethods *methods; /* the I/O methods table */
  78. PRFilePrivate *secret; /* layer dependent data */
  79. PRFileDesc *lower, *higher; /* pointers to adjacent layers */
  80. void (PR_CALLBACK *dtor)(PRFileDesc *fd);
  81. /* A destructor function for layer */
  82. PRDescIdentity identity; /* Identity of this particular layer */
  83. };
  84. /*
  85. ***************************************************************************
  86. ** PRTransmitFileFlags
  87. **
  88. ** Flags for PR_TransmitFile. Pass PR_TRANSMITFILE_CLOSE_SOCKET to
  89. ** PR_TransmitFile if the connection should be closed after the file
  90. ** is transmitted.
  91. ***************************************************************************
  92. */
  93. typedef enum PRTransmitFileFlags {
  94. PR_TRANSMITFILE_KEEP_OPEN = 0, /* socket is left open after file
  95. * is transmitted. */
  96. PR_TRANSMITFILE_CLOSE_SOCKET = 1 /* socket is closed after file
  97. * is transmitted. */
  98. } PRTransmitFileFlags;
  99. /*
  100. **************************************************************************
  101. ** Macros for PRNetAddr
  102. **
  103. ** Address families: PR_AF_INET, PR_AF_INET6, PR_AF_LOCAL
  104. ** IP addresses: PR_INADDR_ANY, PR_INADDR_LOOPBACK, PR_INADDR_BROADCAST
  105. **************************************************************************
  106. */
  107. #ifdef WIN32
  108. #define PR_AF_INET 2
  109. #define PR_AF_LOCAL 1
  110. #define PR_INADDR_ANY (unsigned long)0x00000000
  111. #define PR_INADDR_LOOPBACK 0x7f000001
  112. #define PR_INADDR_BROADCAST (unsigned long)0xffffffff
  113. #else /* WIN32 */
  114. #define PR_AF_INET AF_INET
  115. #define PR_AF_LOCAL AF_UNIX
  116. #define PR_INADDR_ANY INADDR_ANY
  117. #define PR_INADDR_LOOPBACK INADDR_LOOPBACK
  118. #define PR_INADDR_BROADCAST INADDR_BROADCAST
  119. #endif /* WIN32 */
  120. /*
  121. ** Define PR_AF_INET6 in prcpucfg.h with the same
  122. ** value as AF_INET6 on platforms with IPv6 support.
  123. ** Otherwise define it here.
  124. */
  125. #ifndef PR_AF_INET6
  126. #define PR_AF_INET6 100
  127. #endif
  128. #ifndef PR_AF_UNSPEC
  129. #define PR_AF_UNSPEC 0
  130. #endif
  131. /*
  132. **************************************************************************
  133. ** A network address
  134. **
  135. ** Only Internet Protocol (IPv4 and IPv6) addresses are supported.
  136. ** The address family must always represent IPv4 (AF_INET, probably == 2)
  137. ** or IPv6 (AF_INET6).
  138. **************************************************************************
  139. *************************************************************************/
  140. struct PRIPv6Addr {
  141. union {
  142. PRUint8 _S6_u8[16];
  143. PRUint16 _S6_u16[8];
  144. PRUint32 _S6_u32[4];
  145. PRUint64 _S6_u64[2];
  146. } _S6_un;
  147. };
  148. #define pr_s6_addr _S6_un._S6_u8
  149. #define pr_s6_addr16 _S6_un._S6_u16
  150. #define pr_s6_addr32 _S6_un._S6_u32
  151. #define pr_s6_addr64 _S6_un._S6_u64
  152. typedef struct PRIPv6Addr PRIPv6Addr;
  153. union PRNetAddr {
  154. struct {
  155. PRUint16 family; /* address family (0x00ff maskable) */
  156. #ifdef XP_BEOS
  157. char data[10]; /* Be has a smaller structure */
  158. #else
  159. char data[14]; /* raw address data */
  160. #endif
  161. } raw;
  162. struct {
  163. PRUint16 family; /* address family (AF_INET) */
  164. PRUint16 port; /* port number */
  165. PRUint32 ip; /* The actual 32 bits of address */
  166. #ifdef XP_BEOS
  167. char pad[4]; /* Be has a smaller structure */
  168. #else
  169. char pad[8];
  170. #endif
  171. } inet;
  172. struct {
  173. PRUint16 family; /* address family (AF_INET6) */
  174. PRUint16 port; /* port number */
  175. PRUint32 flowinfo; /* routing information */
  176. PRIPv6Addr ip; /* the actual 128 bits of address */
  177. PRUint32 scope_id; /* set of interfaces for a scope */
  178. } ipv6;
  179. #if defined(XP_UNIX) || defined(XP_OS2_EMX)
  180. struct { /* Unix domain socket address */
  181. PRUint16 family; /* address family (AF_UNIX) */
  182. #ifdef XP_OS2
  183. char path[108]; /* null-terminated pathname */
  184. /* bind fails if size is not 108. */
  185. #else
  186. char path[104]; /* null-terminated pathname */
  187. #endif
  188. } local;
  189. #endif
  190. };
  191. /*
  192. ***************************************************************************
  193. ** PRSockOption
  194. **
  195. ** The file descriptors can have predefined options set after they file
  196. ** descriptor is created to change their behavior. Only the options in
  197. ** the following enumeration are supported.
  198. ***************************************************************************
  199. */
  200. typedef enum PRSockOption
  201. {
  202. PR_SockOpt_Nonblocking, /* nonblocking io */
  203. PR_SockOpt_Linger, /* linger on close if data present */
  204. PR_SockOpt_Reuseaddr, /* allow local address reuse */
  205. PR_SockOpt_Keepalive, /* keep connections alive */
  206. PR_SockOpt_RecvBufferSize, /* send buffer size */
  207. PR_SockOpt_SendBufferSize, /* receive buffer size */
  208. PR_SockOpt_IpTimeToLive, /* time to live */
  209. PR_SockOpt_IpTypeOfService, /* type of service and precedence */
  210. PR_SockOpt_AddMember, /* add an IP group membership */
  211. PR_SockOpt_DropMember, /* drop an IP group membership */
  212. PR_SockOpt_McastInterface, /* multicast interface address */
  213. PR_SockOpt_McastTimeToLive, /* multicast timetolive */
  214. PR_SockOpt_McastLoopback, /* multicast loopback */
  215. PR_SockOpt_NoDelay, /* don't delay send to coalesce packets */
  216. PR_SockOpt_MaxSegment, /* maximum segment size */
  217. PR_SockOpt_Broadcast, /* enable broadcast */
  218. PR_SockOpt_Last
  219. } PRSockOption;
  220. typedef struct PRLinger {
  221. PRBool polarity; /* Polarity of the option's setting */
  222. PRIntervalTime linger; /* Time to linger before closing */
  223. } PRLinger;
  224. typedef struct PRMcastRequest {
  225. PRNetAddr mcaddr; /* IP multicast address of group */
  226. PRNetAddr ifaddr; /* local IP address of interface */
  227. } PRMcastRequest;
  228. typedef struct PRSocketOptionData
  229. {
  230. PRSockOption option;
  231. union
  232. {
  233. PRUintn ip_ttl; /* IP time to live */
  234. PRUintn mcast_ttl; /* IP multicast time to live */
  235. PRUintn tos; /* IP type of service and precedence */
  236. PRBool non_blocking; /* Non-blocking (network) I/O */
  237. PRBool reuse_addr; /* Allow local address reuse */
  238. PRBool keep_alive; /* Keep connections alive */
  239. PRBool mcast_loopback; /* IP multicast loopback */
  240. PRBool no_delay; /* Don't delay send to coalesce packets */
  241. PRBool broadcast; /* Enable broadcast */
  242. PRSize max_segment; /* Maximum segment size */
  243. PRSize recv_buffer_size; /* Receive buffer size */
  244. PRSize send_buffer_size; /* Send buffer size */
  245. PRLinger linger; /* Time to linger on close if data present */
  246. PRMcastRequest add_member; /* add an IP group membership */
  247. PRMcastRequest drop_member; /* Drop an IP group membership */
  248. PRNetAddr mcast_if; /* multicast interface address */
  249. } value;
  250. } PRSocketOptionData;
  251. /*
  252. ***************************************************************************
  253. ** PRIOVec
  254. **
  255. ** The I/O vector is used by the write vector method to describe the areas
  256. ** that are affected by the ouput operation.
  257. ***************************************************************************
  258. */
  259. typedef struct PRIOVec {
  260. char *iov_base;
  261. int iov_len;
  262. } PRIOVec;
  263. /*
  264. ***************************************************************************
  265. ** Discover what type of socket is being described by the file descriptor.
  266. ***************************************************************************
  267. */
  268. typedef enum PRDescType
  269. {
  270. PR_DESC_FILE = 1,
  271. PR_DESC_SOCKET_TCP = 2,
  272. PR_DESC_SOCKET_UDP = 3,
  273. PR_DESC_LAYERED = 4,
  274. PR_DESC_PIPE = 5
  275. } PRDescType;
  276. typedef enum PRSeekWhence {
  277. PR_SEEK_SET = 0,
  278. PR_SEEK_CUR = 1,
  279. PR_SEEK_END = 2
  280. } PRSeekWhence;
  281. NSPR_API(PRDescType) PR_GetDescType(PRFileDesc *file);
  282. /*
  283. ***************************************************************************
  284. ** PRIOMethods
  285. **
  286. ** The I/O methods table provides procedural access to the functions of
  287. ** the file descriptor. It is the responsibility of a layer implementor
  288. ** to provide suitable functions at every entry point. If a layer provides
  289. ** no functionality, it should call the next lower(higher) function of the
  290. ** same name (e.g., return fd->lower->method->close(fd->lower));
  291. **
  292. ** Not all functions are implemented for all types of files. In cases where
  293. ** that is true, the function will return a error indication with an error
  294. ** code of PR_INVALID_METHOD_ERROR.
  295. ***************************************************************************
  296. */
  297. typedef PRStatus (PR_CALLBACK *PRCloseFN)(PRFileDesc *fd);
  298. typedef PRInt32 (PR_CALLBACK *PRReadFN)(PRFileDesc *fd, void *buf, PRInt32 amount);
  299. typedef PRInt32 (PR_CALLBACK *PRWriteFN)(PRFileDesc *fd, const void *buf, PRInt32 amount);
  300. typedef PRInt32 (PR_CALLBACK *PRAvailableFN)(PRFileDesc *fd);
  301. typedef PRInt64 (PR_CALLBACK *PRAvailable64FN)(PRFileDesc *fd);
  302. typedef PRStatus (PR_CALLBACK *PRFsyncFN)(PRFileDesc *fd);
  303. typedef PROffset32 (PR_CALLBACK *PRSeekFN)(PRFileDesc *fd, PROffset32 offset, PRSeekWhence how);
  304. typedef PROffset64 (PR_CALLBACK *PRSeek64FN)(PRFileDesc *fd, PROffset64 offset, PRSeekWhence how);
  305. typedef PRStatus (PR_CALLBACK *PRFileInfoFN)(PRFileDesc *fd, PRFileInfo *info);
  306. typedef PRStatus (PR_CALLBACK *PRFileInfo64FN)(PRFileDesc *fd, PRFileInfo64 *info);
  307. typedef PRInt32 (PR_CALLBACK *PRWritevFN)(
  308. PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size,
  309. PRIntervalTime timeout);
  310. typedef PRStatus (PR_CALLBACK *PRConnectFN)(
  311. PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout);
  312. typedef PRFileDesc* (PR_CALLBACK *PRAcceptFN) (
  313. PRFileDesc *fd, PRNetAddr *addr, PRIntervalTime timeout);
  314. typedef PRStatus (PR_CALLBACK *PRBindFN)(PRFileDesc *fd, const PRNetAddr *addr);
  315. typedef PRStatus (PR_CALLBACK *PRListenFN)(PRFileDesc *fd, PRIntn backlog);
  316. typedef PRStatus (PR_CALLBACK *PRShutdownFN)(PRFileDesc *fd, PRIntn how);
  317. typedef PRInt32 (PR_CALLBACK *PRRecvFN)(
  318. PRFileDesc *fd, void *buf, PRInt32 amount,
  319. PRIntn flags, PRIntervalTime timeout);
  320. typedef PRInt32 (PR_CALLBACK *PRSendFN) (
  321. PRFileDesc *fd, const void *buf, PRInt32 amount,
  322. PRIntn flags, PRIntervalTime timeout);
  323. typedef PRInt32 (PR_CALLBACK *PRRecvfromFN)(
  324. PRFileDesc *fd, void *buf, PRInt32 amount,
  325. PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout);
  326. typedef PRInt32 (PR_CALLBACK *PRSendtoFN)(
  327. PRFileDesc *fd, const void *buf, PRInt32 amount,
  328. PRIntn flags, const PRNetAddr *addr, PRIntervalTime timeout);
  329. typedef PRInt16 (PR_CALLBACK *PRPollFN)(
  330. PRFileDesc *fd, PRInt16 in_flags, PRInt16 *out_flags);
  331. typedef PRInt32 (PR_CALLBACK *PRAcceptreadFN)(
  332. PRFileDesc *sd, PRFileDesc **nd, PRNetAddr **raddr,
  333. void *buf, PRInt32 amount, PRIntervalTime t);
  334. typedef PRInt32 (PR_CALLBACK *PRTransmitfileFN)(
  335. PRFileDesc *sd, PRFileDesc *fd, const void *headers,
  336. PRInt32 hlen, PRTransmitFileFlags flags, PRIntervalTime t);
  337. typedef PRStatus (PR_CALLBACK *PRGetsocknameFN)(PRFileDesc *fd, PRNetAddr *addr);
  338. typedef PRStatus (PR_CALLBACK *PRGetpeernameFN)(PRFileDesc *fd, PRNetAddr *addr);
  339. typedef PRStatus (PR_CALLBACK *PRGetsocketoptionFN)(
  340. PRFileDesc *fd, PRSocketOptionData *data);
  341. typedef PRStatus (PR_CALLBACK *PRSetsocketoptionFN)(
  342. PRFileDesc *fd, const PRSocketOptionData *data);
  343. typedef PRInt32 (PR_CALLBACK *PRSendfileFN)(
  344. PRFileDesc *networkSocket, PRSendFileData *sendData,
  345. PRTransmitFileFlags flags, PRIntervalTime timeout);
  346. typedef PRStatus (PR_CALLBACK *PRConnectcontinueFN)(
  347. PRFileDesc *fd, PRInt16 out_flags);
  348. typedef PRIntn (PR_CALLBACK *PRReservedFN)(PRFileDesc *fd);
  349. struct PRIOMethods {
  350. PRDescType file_type; /* Type of file represented (tos) */
  351. PRCloseFN close; /* close file and destroy descriptor */
  352. PRReadFN read; /* read up to specified bytes into buffer */
  353. PRWriteFN write; /* write specified bytes from buffer */
  354. PRAvailableFN available; /* determine number of bytes available */
  355. PRAvailable64FN available64; /* ditto, 64 bit */
  356. PRFsyncFN fsync; /* flush all buffers to permanent store */
  357. PRSeekFN seek; /* position the file to the desired place */
  358. PRSeek64FN seek64; /* ditto, 64 bit */
  359. PRFileInfoFN fileInfo; /* Get information about an open file */
  360. PRFileInfo64FN fileInfo64; /* ditto, 64 bit */
  361. PRWritevFN writev; /* Write segments as described by iovector */
  362. PRConnectFN connect; /* Connect to the specified (net) address */
  363. PRAcceptFN accept; /* Accept a connection for a (net) peer */
  364. PRBindFN bind; /* Associate a (net) address with the fd */
  365. PRListenFN listen; /* Prepare to listen for (net) connections */
  366. PRShutdownFN shutdown; /* Shutdown a (net) connection */
  367. PRRecvFN recv; /* Solicit up the the specified bytes */
  368. PRSendFN send; /* Send all the bytes specified */
  369. PRRecvfromFN recvfrom; /* Solicit (net) bytes and report source */
  370. PRSendtoFN sendto; /* Send bytes to (net) address specified */
  371. PRPollFN poll; /* Test the fd to see if it is ready */
  372. PRAcceptreadFN acceptread; /* Accept and read on a new (net) fd */
  373. PRTransmitfileFN transmitfile; /* Transmit at entire file */
  374. PRGetsocknameFN getsockname; /* Get (net) address associated with fd */
  375. PRGetpeernameFN getpeername; /* Get peer's (net) address */
  376. PRReservedFN reserved_fn_6; /* reserved for future use */
  377. PRReservedFN reserved_fn_5; /* reserved for future use */
  378. PRGetsocketoptionFN getsocketoption;
  379. /* Get current setting of specified option */
  380. PRSetsocketoptionFN setsocketoption;
  381. /* Set value of specified option */
  382. PRSendfileFN sendfile; /* Send a (partial) file with header/trailer*/
  383. PRConnectcontinueFN connectcontinue;
  384. /* Continue a nonblocking connect */
  385. PRReservedFN reserved_fn_3; /* reserved for future use */
  386. PRReservedFN reserved_fn_2; /* reserved for future use */
  387. PRReservedFN reserved_fn_1; /* reserved for future use */
  388. PRReservedFN reserved_fn_0; /* reserved for future use */
  389. };
  390. /*
  391. **************************************************************************
  392. * FUNCTION: PR_GetSpecialFD
  393. * DESCRIPTION: Get the file descriptor that represents the standard input,
  394. * output, or error stream.
  395. * INPUTS:
  396. * PRSpecialFD id
  397. * A value indicating the type of stream desired:
  398. * PR_StandardInput: standard input
  399. * PR_StandardOuput: standard output
  400. * PR_StandardError: standard error
  401. * OUTPUTS: none
  402. * RETURNS: PRFileDesc *
  403. * If the argument is valid, PR_GetSpecialFD returns a file descriptor
  404. * that represents the corresponding standard I/O stream. Otherwise,
  405. * PR_GetSpecialFD returns NULL and sets error PR_INVALID_ARGUMENT_ERROR.
  406. **************************************************************************
  407. */
  408. typedef enum PRSpecialFD
  409. {
  410. PR_StandardInput, /* standard input */
  411. PR_StandardOutput, /* standard output */
  412. PR_StandardError /* standard error */
  413. } PRSpecialFD;
  414. NSPR_API(PRFileDesc*) PR_GetSpecialFD(PRSpecialFD id);
  415. #define PR_STDIN PR_GetSpecialFD(PR_StandardInput)
  416. #define PR_STDOUT PR_GetSpecialFD(PR_StandardOutput)
  417. #define PR_STDERR PR_GetSpecialFD(PR_StandardError)
  418. /*
  419. **************************************************************************
  420. * Layering file descriptors
  421. *
  422. * File descriptors may be layered. Each layer has it's own identity.
  423. * Identities are allocated by the runtime and are to be associated
  424. * (by the layer implementor) with all layers that are of that type.
  425. * It is then possible to scan the chain of layers and find a layer
  426. * that one recongizes and therefore predict that it will implement
  427. * a desired protocol.
  428. *
  429. * There are three well-known identities:
  430. * PR_INVALID_IO_LAYER => an invalid layer identity, for error return
  431. * PR_TOP_IO_LAYER => the identity of the top of the stack
  432. * PR_NSPR_IO_LAYER => the identity used by NSPR proper
  433. * PR_TOP_IO_LAYER may be used as a shorthand for identifying the topmost
  434. * layer of an existing stack. Ie., the following two constructs are
  435. * equivalent.
  436. *
  437. * rv = PR_PushIOLayer(stack, PR_TOP_IO_LAYER, my_layer);
  438. * rv = PR_PushIOLayer(stack, PR_GetLayersIdentity(stack), my_layer)
  439. *
  440. * A string may be associated with the creation of the identity. It
  441. * will be copied by the runtime. If queried the runtime will return
  442. * a reference to that copied string (not yet another copy). There
  443. * is no facility for deleting an identity.
  444. **************************************************************************
  445. */
  446. #define PR_IO_LAYER_HEAD (PRDescIdentity)-3
  447. #define PR_INVALID_IO_LAYER (PRDescIdentity)-1
  448. #define PR_TOP_IO_LAYER (PRDescIdentity)-2
  449. #define PR_NSPR_IO_LAYER (PRDescIdentity)0
  450. NSPR_API(PRDescIdentity) PR_GetUniqueIdentity(const char *layer_name);
  451. NSPR_API(const char*) PR_GetNameForIdentity(PRDescIdentity ident);
  452. NSPR_API(PRDescIdentity) PR_GetLayersIdentity(PRFileDesc* fd);
  453. NSPR_API(PRFileDesc*) PR_GetIdentitiesLayer(PRFileDesc* fd_stack, PRDescIdentity id);
  454. /*
  455. **************************************************************************
  456. * PR_GetDefaultIOMethods: Accessing the default methods table.
  457. * You may get a pointer to the default methods table by calling this function.
  458. * You may then select any elements from that table with which to build your
  459. * layer's methods table. You may NOT modify the table directly.
  460. **************************************************************************
  461. */
  462. NSPR_API(const PRIOMethods *) PR_GetDefaultIOMethods(void);
  463. /*
  464. **************************************************************************
  465. * Creating a layer
  466. *
  467. * A new layer may be allocated by calling PR_CreateIOLayerStub(). The
  468. * file descriptor returned will contain the pointer to the methods table
  469. * provided. The runtime will not modify the table nor test its correctness.
  470. **************************************************************************
  471. */
  472. NSPR_API(PRFileDesc*) PR_CreateIOLayerStub(
  473. PRDescIdentity ident, const PRIOMethods *methods);
  474. /*
  475. **************************************************************************
  476. * Creating a layer
  477. *
  478. * A new stack may be created by calling PR_CreateIOLayer(). The
  479. * file descriptor returned will point to the top of the stack, which has
  480. * the layer 'fd' as the topmost layer.
  481. *
  482. * NOTE: This function creates a new style stack, which has a fixed, dummy
  483. * header. The old style stack, created by a call to PR_PushIOLayer,
  484. * results in modifying contents of the top layer of the stack, when
  485. * pushing and popping layers of the stack.
  486. **************************************************************************
  487. */
  488. NSPR_API(PRFileDesc*) PR_CreateIOLayer(PRFileDesc* fd);
  489. /*
  490. **************************************************************************
  491. * Pushing a layer
  492. *
  493. * A file descriptor (perhaps allocated using PR_CreateIOLayerStub()) may
  494. * be pushed into an existing stack of file descriptors at any point the
  495. * caller deems appropriate. The new layer will be inserted into the stack
  496. * just above the layer with the indicated identity.
  497. *
  498. * Note: Even if the identity parameter indicates the top-most layer of
  499. * the stack, the value of the file descriptor describing the original
  500. * stack will not change.
  501. **************************************************************************
  502. */
  503. NSPR_API(PRStatus) PR_PushIOLayer(
  504. PRFileDesc *fd_stack, PRDescIdentity id, PRFileDesc *layer);
  505. /*
  506. **************************************************************************
  507. * Popping a layer
  508. *
  509. * A layer may be popped from a stack by indicating the identity of the
  510. * layer to be removed. If found, a pointer to the removed object will
  511. * be returned to the caller. The object then becomes the responsibility
  512. * of the caller.
  513. *
  514. * Note: Even if the identity indicates the top layer of the stack, the
  515. * reference returned will not be the file descriptor for the stack and
  516. * that file descriptor will remain valid.
  517. **************************************************************************
  518. */
  519. NSPR_API(PRFileDesc*) PR_PopIOLayer(PRFileDesc *fd_stack, PRDescIdentity id);
  520. /*
  521. **************************************************************************
  522. * FUNCTION: PR_Open
  523. * DESCRIPTION: Open a file for reading, writing, or both.
  524. * INPUTS:
  525. * const char *name
  526. * The path name of the file to be opened
  527. * PRIntn flags
  528. * The file status flags.
  529. * It is a bitwise OR of the following bit flags (only one of
  530. * the first three flags below may be used):
  531. * PR_RDONLY Open for reading only.
  532. * PR_WRONLY Open for writing only.
  533. * PR_RDWR Open for reading and writing.
  534. * PR_CREATE_FILE If the file does not exist, the file is created
  535. * If the file exists, this flag has no effect.
  536. * PR_SYNC If set, each write will wait for both the file data
  537. * and file status to be physically updated.
  538. * PR_APPEND The file pointer is set to the end of
  539. * the file prior to each write.
  540. * PR_TRUNCATE If the file exists, its length is truncated to 0.
  541. * PR_EXCL With PR_CREATE_FILE, if the file does not exist,
  542. * the file is created. If the file already
  543. * exists, no action and NULL is returned
  544. *
  545. * PRIntn mode
  546. * The access permission bits of the file mode, if the file is
  547. * created when PR_CREATE_FILE is on.
  548. * OUTPUTS: None
  549. * RETURNS: PRFileDesc *
  550. * If the file is successfully opened,
  551. * returns a pointer to the PRFileDesc
  552. * created for the newly opened file.
  553. * Returns a NULL pointer if the open
  554. * failed.
  555. * SIDE EFFECTS:
  556. * RESTRICTIONS:
  557. * MEMORY:
  558. * The return value, if not NULL, points to a dynamically allocated
  559. * PRFileDesc object.
  560. * ALGORITHM:
  561. **************************************************************************
  562. */
  563. /* Open flags */
  564. #define PR_RDONLY 0x01
  565. #define PR_WRONLY 0x02
  566. #define PR_RDWR 0x04
  567. #define PR_CREATE_FILE 0x08
  568. #define PR_APPEND 0x10
  569. #define PR_TRUNCATE 0x20
  570. #define PR_SYNC 0x40
  571. #define PR_EXCL 0x80
  572. /*
  573. ** File modes ....
  574. **
  575. ** CAVEAT: 'mode' is currently only applicable on UNIX platforms.
  576. ** The 'mode' argument may be ignored by PR_Open on other platforms.
  577. **
  578. ** 00400 Read by owner.
  579. ** 00200 Write by owner.
  580. ** 00100 Execute (search if a directory) by owner.
  581. ** 00040 Read by group.
  582. ** 00020 Write by group.
  583. ** 00010 Execute by group.
  584. ** 00004 Read by others.
  585. ** 00002 Write by others
  586. ** 00001 Execute by others.
  587. **
  588. */
  589. NSPR_API(PRFileDesc*) PR_Open(const char *name, PRIntn flags, PRIntn mode);
  590. /*
  591. **************************************************************************
  592. * FUNCTION: PR_OpenFile
  593. * DESCRIPTION:
  594. * Open a file for reading, writing, or both.
  595. * PR_OpenFile has the same prototype as PR_Open but implements
  596. * the specified file mode where possible.
  597. **************************************************************************
  598. */
  599. /* File mode bits */
  600. #define PR_IRWXU 00700 /* read, write, execute/search by owner */
  601. #define PR_IRUSR 00400 /* read permission, owner */
  602. #define PR_IWUSR 00200 /* write permission, owner */
  603. #define PR_IXUSR 00100 /* execute/search permission, owner */
  604. #define PR_IRWXG 00070 /* read, write, execute/search by group */
  605. #define PR_IRGRP 00040 /* read permission, group */
  606. #define PR_IWGRP 00020 /* write permission, group */
  607. #define PR_IXGRP 00010 /* execute/search permission, group */
  608. #define PR_IRWXO 00007 /* read, write, execute/search by others */
  609. #define PR_IROTH 00004 /* read permission, others */
  610. #define PR_IWOTH 00002 /* write permission, others */
  611. #define PR_IXOTH 00001 /* execute/search permission, others */
  612. NSPR_API(PRFileDesc*) PR_OpenFile(
  613. const char *name, PRIntn flags, PRIntn mode);
  614. #ifdef MOZ_UNICODE
  615. /*
  616. * EXPERIMENTAL: This function may be removed in a future release.
  617. */
  618. NSPR_API(PRFileDesc*) PR_OpenFileUTF16(
  619. const PRUnichar *name, PRIntn flags, PRIntn mode);
  620. #endif /* MOZ_UNICODE */
  621. /*
  622. **************************************************************************
  623. * FUNCTION: PR_Close
  624. * DESCRIPTION:
  625. * Close a file or socket.
  626. * INPUTS:
  627. * PRFileDesc *fd
  628. * a pointer to a PRFileDesc.
  629. * OUTPUTS:
  630. * None.
  631. * RETURN:
  632. * PRStatus
  633. * SIDE EFFECTS:
  634. * RESTRICTIONS:
  635. * None.
  636. * MEMORY:
  637. * The dynamic memory pointed to by the argument fd is freed.
  638. **************************************************************************
  639. */
  640. NSPR_API(PRStatus) PR_Close(PRFileDesc *fd);
  641. /*
  642. **************************************************************************
  643. * FUNCTION: PR_Read
  644. * DESCRIPTION:
  645. * Read bytes from a file or socket.
  646. * The operation will block until either an end of stream indication is
  647. * encountered, some positive number of bytes are transferred, or there
  648. * is an error. No more than 'amount' bytes will be transferred.
  649. * INPUTS:
  650. * PRFileDesc *fd
  651. * pointer to the PRFileDesc object for the file or socket
  652. * void *buf
  653. * pointer to a buffer to hold the data read in.
  654. * PRInt32 amount
  655. * the size of 'buf' (in bytes)
  656. * OUTPUTS:
  657. * RETURN:
  658. * PRInt32
  659. * a positive number indicates the number of bytes actually read in.
  660. * 0 means end of file is reached or the network connection is closed.
  661. * -1 indicates a failure. The reason for the failure is obtained
  662. * by calling PR_GetError().
  663. * SIDE EFFECTS:
  664. * data is written into the buffer pointed to by 'buf'.
  665. * RESTRICTIONS:
  666. * None.
  667. * MEMORY:
  668. * N/A
  669. * ALGORITHM:
  670. * N/A
  671. **************************************************************************
  672. */
  673. NSPR_API(PRInt32) PR_Read(PRFileDesc *fd, void *buf, PRInt32 amount);
  674. /*
  675. ***************************************************************************
  676. * FUNCTION: PR_Write
  677. * DESCRIPTION:
  678. * Write a specified number of bytes to a file or socket. The thread
  679. * invoking this function blocks until all the data is written.
  680. * INPUTS:
  681. * PRFileDesc *fd
  682. * pointer to a PRFileDesc object that refers to a file or socket
  683. * const void *buf
  684. * pointer to the buffer holding the data
  685. * PRInt32 amount
  686. * amount of data in bytes to be written from the buffer
  687. * OUTPUTS:
  688. * None.
  689. * RETURN: PRInt32
  690. * A positive number indicates the number of bytes successfully written.
  691. * A -1 is an indication that the operation failed. The reason
  692. * for the failure is obtained by calling PR_GetError().
  693. ***************************************************************************
  694. */
  695. NSPR_API(PRInt32) PR_Write(PRFileDesc *fd,const void *buf,PRInt32 amount);
  696. /*
  697. ***************************************************************************
  698. * FUNCTION: PR_Writev
  699. * DESCRIPTION:
  700. * Write data to a socket. The data is organized in a PRIOVec array. The
  701. * operation will block until all the data is written or the operation
  702. * fails.
  703. * INPUTS:
  704. * PRFileDesc *fd
  705. * Pointer that points to a PRFileDesc object for a socket.
  706. * const PRIOVec *iov
  707. * An array of PRIOVec. PRIOVec is a struct with the following
  708. * two fields:
  709. * char *iov_base;
  710. * int iov_len;
  711. * PRInt32 iov_size
  712. * Number of elements in the iov array. The value of this
  713. * argument must not be greater than PR_MAX_IOVECTOR_SIZE.
  714. * If it is, the method will fail (PR_BUFFER_OVERFLOW_ERROR).
  715. * PRIntervalTime timeout
  716. * Time limit for completion of the entire write operation.
  717. * OUTPUTS:
  718. * None
  719. * RETURN:
  720. * A positive number indicates the number of bytes successfully written.
  721. * A -1 is an indication that the operation failed. The reason
  722. * for the failure is obtained by calling PR_GetError().
  723. ***************************************************************************
  724. */
  725. #define PR_MAX_IOVECTOR_SIZE 16 /* 'iov_size' must be <= */
  726. NSPR_API(PRInt32) PR_Writev(
  727. PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size,
  728. PRIntervalTime timeout);
  729. /*
  730. ***************************************************************************
  731. * FUNCTION: PR_Delete
  732. * DESCRIPTION:
  733. * Delete a file from the filesystem. The operation may fail if the
  734. * file is open.
  735. * INPUTS:
  736. * const char *name
  737. * Path name of the file to be deleted.
  738. * OUTPUTS:
  739. * None.
  740. * RETURN: PRStatus
  741. * The function returns PR_SUCCESS if the file is successfully
  742. * deleted, otherwise it returns PR_FAILURE.
  743. ***************************************************************************
  744. */
  745. NSPR_API(PRStatus) PR_Delete(const char *name);
  746. /**************************************************************************/
  747. typedef enum PRFileType
  748. {
  749. PR_FILE_FILE = 1,
  750. PR_FILE_DIRECTORY = 2,
  751. PR_FILE_OTHER = 3
  752. } PRFileType;
  753. struct PRFileInfo {
  754. PRFileType type; /* Type of file */
  755. PROffset32 size; /* Size, in bytes, of file's contents */
  756. PRTime creationTime; /* Creation time per definition of PRTime */
  757. PRTime modifyTime; /* Last modification time per definition of PRTime */
  758. };
  759. struct PRFileInfo64 {
  760. PRFileType type; /* Type of file */
  761. PROffset64 size; /* Size, in bytes, of file's contents */
  762. PRTime creationTime; /* Creation time per definition of PRTime */
  763. PRTime modifyTime; /* Last modification time per definition of PRTime */
  764. };
  765. /****************************************************************************
  766. * FUNCTION: PR_GetFileInfo, PR_GetFileInfo64
  767. * DESCRIPTION:
  768. * Get the information about the file with the given path name. This is
  769. * applicable only to NSFileDesc describing 'file' types (see
  770. * INPUTS:
  771. * const char *fn
  772. * path name of the file
  773. * OUTPUTS:
  774. * PRFileInfo *info
  775. * Information about the given file is written into the file
  776. * information object pointer to by 'info'.
  777. * RETURN: PRStatus
  778. * PR_GetFileInfo returns PR_SUCCESS if file information is successfully
  779. * obtained, otherwise it returns PR_FAILURE.
  780. ***************************************************************************
  781. */
  782. NSPR_API(PRStatus) PR_GetFileInfo(const char *fn, PRFileInfo *info);
  783. NSPR_API(PRStatus) PR_GetFileInfo64(const char *fn, PRFileInfo64 *info);
  784. #ifdef MOZ_UNICODE
  785. /*
  786. * EXPERIMENTAL: This function may be removed in a future release.
  787. */
  788. NSPR_API(PRStatus) PR_GetFileInfo64UTF16(const PRUnichar *fn, PRFileInfo64 *info);
  789. #endif /* MOZ_UNICODE */
  790. /*
  791. **************************************************************************
  792. * FUNCTION: PR_GetOpenFileInfo, PR_GetOpenFileInfo64
  793. * DESCRIPTION:
  794. * Get information about an open file referred to by the
  795. * given PRFileDesc object.
  796. * INPUTS:
  797. * const PRFileDesc *fd
  798. * A reference to a valid, open file.
  799. * OUTPUTS:
  800. * Same as PR_GetFileInfo, PR_GetFileInfo64
  801. * RETURN: PRStatus
  802. * PR_GetFileInfo returns PR_SUCCESS if file information is successfully
  803. * obtained, otherwise it returns PR_FAILURE.
  804. ***************************************************************************
  805. */
  806. NSPR_API(PRStatus) PR_GetOpenFileInfo(PRFileDesc *fd, PRFileInfo *info);
  807. NSPR_API(PRStatus) PR_GetOpenFileInfo64(PRFileDesc *fd, PRFileInfo64 *info);
  808. /*
  809. **************************************************************************
  810. * FUNCTION: PR_Rename
  811. * DESCRIPTION:
  812. * Rename a file from the old name 'from' to the new name 'to'.
  813. * INPUTS:
  814. * const char *from
  815. * The old name of the file to be renamed.
  816. * const char *to
  817. * The new name of the file.
  818. * OUTPUTS:
  819. * None.
  820. * RETURN: PRStatus
  821. **************************************************************************
  822. */
  823. NSPR_API(PRStatus) PR_Rename(const char *from, const char *to);
  824. /*
  825. *************************************************************************
  826. * FUNCTION: PR_Access
  827. * DESCRIPTION:
  828. * Determine accessibility of a file.
  829. * INPUTS:
  830. * const char *name
  831. * path name of the file
  832. * PRAccessHow how
  833. * specifies which access permission to check for.
  834. * It can be one of the following values:
  835. * PR_ACCESS_READ_OK Test for read permission
  836. * PR_ACCESS_WRITE_OK Test for write permission
  837. * PR_ACCESS_EXISTS Check existence of file
  838. * OUTPUTS:
  839. * None.
  840. * RETURN: PRStatus
  841. * PR_SUCCESS is returned if the requested access is permitted.
  842. * Otherwise, PR_FAILURE is returned. Additional information
  843. * regarding the reason for the failure may be retrieved from
  844. * PR_GetError().
  845. *************************************************************************
  846. */
  847. typedef enum PRAccessHow {
  848. PR_ACCESS_EXISTS = 1,
  849. PR_ACCESS_WRITE_OK = 2,
  850. PR_ACCESS_READ_OK = 3
  851. } PRAccessHow;
  852. NSPR_API(PRStatus) PR_Access(const char *name, PRAccessHow how);
  853. /*
  854. *************************************************************************
  855. * FUNCTION: PR_Seek, PR_Seek64
  856. * DESCRIPTION:
  857. * Moves read-write file offset
  858. * INPUTS:
  859. * PRFileDesc *fd
  860. * Pointer to a PRFileDesc object.
  861. * PROffset32, PROffset64 offset
  862. * Specifies a value, in bytes, that is used in conjunction
  863. * with the 'whence' parameter to set the file pointer. A
  864. * negative value causes seeking in the reverse direction.
  865. * PRSeekWhence whence
  866. * Specifies how to interpret the 'offset' parameter in setting
  867. * the file pointer associated with the 'fd' parameter.
  868. * Values for the 'whence' parameter are:
  869. * PR_SEEK_SET Sets the file pointer to the value of the
  870. * 'offset' parameter
  871. * PR_SEEK_CUR Sets the file pointer to its current location
  872. * plus the value of the offset parameter.
  873. * PR_SEEK_END Sets the file pointer to the size of the
  874. * file plus the value of the offset parameter.
  875. * OUTPUTS:
  876. * None.
  877. * RETURN: PROffset32, PROffset64
  878. * Upon successful completion, the resulting pointer location,
  879. * measured in bytes from the beginning of the file, is returned.
  880. * If the PR_Seek() function fails, the file offset remains
  881. * unchanged, and the returned value is -1. The error code can
  882. * then be retrieved via PR_GetError().
  883. *************************************************************************
  884. */
  885. NSPR_API(PROffset32) PR_Seek(PRFileDesc *fd, PROffset32 offset, PRSeekWhence whence);
  886. NSPR_API(PROffset64) PR_Seek64(PRFileDesc *fd, PROffset64 offset, PRSeekWhence whence);
  887. /*
  888. ************************************************************************
  889. * FUNCTION: PR_Available
  890. * DESCRIPTION:
  891. * Determine the amount of data in bytes available for reading
  892. * in the given file or socket.
  893. * INPUTS:
  894. * PRFileDesc *fd
  895. * Pointer to a PRFileDesc object that refers to a file or
  896. * socket.
  897. * OUTPUTS:
  898. * None
  899. * RETURN: PRInt32, PRInt64
  900. * Upon successful completion, PR_Available returns the number of
  901. * bytes beyond the current read pointer that is available for
  902. * reading. Otherwise, it returns a -1 and the reason for the
  903. * failure can be retrieved via PR_GetError().
  904. ************************************************************************
  905. */
  906. NSPR_API(PRInt32) PR_Available(PRFileDesc *fd);
  907. NSPR_API(PRInt64) PR_Available64(PRFileDesc *fd);
  908. /*
  909. ************************************************************************
  910. * FUNCTION: PR_Sync
  911. * DESCRIPTION:
  912. * Sync any buffered data for a fd to its backing device (disk).
  913. * INPUTS:
  914. * PRFileDesc *fd
  915. * Pointer to a PRFileDesc object that refers to a file or
  916. * socket
  917. * OUTPUTS:
  918. * None
  919. * RETURN: PRStatus
  920. * PR_SUCCESS is returned if the requested access is permitted.
  921. * Otherwise, PR_FAILURE is returned.
  922. ************************************************************************
  923. */
  924. NSPR_API(PRStatus) PR_Sync(PRFileDesc *fd);
  925. /************************************************************************/
  926. struct PRDirEntry {
  927. const char *name; /* name of entry, relative to directory name */
  928. };
  929. #ifdef MOZ_UNICODE
  930. struct PRDirEntryUTF16 {
  931. const PRUnichar *name; /* name of entry in UTF16, relative to
  932. * directory name */
  933. };
  934. #endif /* MOZ_UNICODE */
  935. #if !defined(NO_NSPR_10_SUPPORT)
  936. #define PR_DirName(dirEntry) (dirEntry->name)
  937. #endif
  938. /*
  939. *************************************************************************
  940. * FUNCTION: PR_OpenDir
  941. * DESCRIPTION:
  942. * Open the directory by the given name
  943. * INPUTS:
  944. * const char *name
  945. * path name of the directory to be opened
  946. * OUTPUTS:
  947. * None
  948. * RETURN: PRDir *
  949. * If the directory is sucessfully opened, a PRDir object is
  950. * dynamically allocated and a pointer to it is returned.
  951. * If the directory cannot be opened, a NULL pointer is returned.
  952. * MEMORY:
  953. * Upon successful completion, the return value points to
  954. * dynamically allocated memory.
  955. *************************************************************************
  956. */
  957. NSPR_API(PRDir*) PR_OpenDir(const char *name);
  958. #ifdef MOZ_UNICODE
  959. /*
  960. * EXPERIMENTAL: This function may be removed in a future release.
  961. */
  962. NSPR_API(PRDirUTF16*) PR_OpenDirUTF16(const PRUnichar *name);
  963. #endif /* MOZ_UNICODE */
  964. /*
  965. *************************************************************************
  966. * FUNCTION: PR_ReadDir
  967. * DESCRIPTION:
  968. * INPUTS:
  969. * PRDir *dir
  970. * pointer to a PRDir object that designates an open directory
  971. * PRDirFlags flags
  972. * PR_SKIP_NONE Do not skip any files
  973. * PR_SKIP_DOT Skip the directory entry "." that
  974. * represents the current directory
  975. * PR_SKIP_DOT_DOT Skip the directory entry ".." that
  976. * represents the parent directory.
  977. * PR_SKIP_BOTH Skip both '.' and '..'
  978. * PR_SKIP_HIDDEN Skip hidden files
  979. * OUTPUTS:
  980. * RETURN: PRDirEntry*
  981. * Returns a pointer to the next entry in the directory. Returns
  982. * a NULL pointer upon reaching the end of the directory or when an
  983. * error occurs. The actual reason can be retrieved via PR_GetError().
  984. *************************************************************************
  985. */
  986. typedef enum PRDirFlags {
  987. PR_SKIP_NONE = 0x0,
  988. PR_SKIP_DOT = 0x1,
  989. PR_SKIP_DOT_DOT = 0x2,
  990. PR_SKIP_BOTH = 0x3,
  991. PR_SKIP_HIDDEN = 0x4
  992. } PRDirFlags;
  993. NSPR_API(PRDirEntry*) PR_ReadDir(PRDir *dir, PRDirFlags flags);
  994. #ifdef MOZ_UNICODE
  995. /*
  996. * EXPERIMENTAL: This function may be removed in a future release.
  997. */
  998. NSPR_API(PRDirEntryUTF16*) PR_ReadDirUTF16(PRDirUTF16 *dir, PRDirFlags flags);
  999. #endif /* MOZ_UNICODE */
  1000. /*
  1001. *************************************************************************
  1002. * FUNCTION: PR_CloseDir
  1003. * DESCRIPTION:
  1004. * Close the specified directory.
  1005. * INPUTS:
  1006. * PRDir *dir
  1007. * The directory to be closed.
  1008. * OUTPUTS:
  1009. * None
  1010. * RETURN: PRStatus
  1011. * If successful, will return a status of PR_SUCCESS. Otherwise
  1012. * a value of PR_FAILURE. The reason for the failure may be re-
  1013. * trieved using PR_GetError().
  1014. *************************************************************************
  1015. */
  1016. NSPR_API(PRStatus) PR_CloseDir(PRDir *dir);
  1017. #ifdef MOZ_UNICODE
  1018. /*
  1019. * EXPERIMENTAL: This function may be removed in a future release.
  1020. */
  1021. NSPR_API(PRStatus) PR_CloseDirUTF16(PRDirUTF16 *dir);
  1022. #endif /* MOZ_UNICODE */
  1023. /*
  1024. *************************************************************************
  1025. * FUNCTION: PR_MkDir
  1026. * DESCRIPTION:
  1027. * Create a new directory with the given name and access mode.
  1028. * INPUTS:
  1029. * const char *name
  1030. * The name of the directory to be created. All the path components
  1031. * up to but not including the leaf component must already exist.
  1032. * PRIntn mode
  1033. * See 'mode' definiton in PR_Open().
  1034. * OUTPUTS:
  1035. * None
  1036. * RETURN: PRStatus
  1037. * If successful, will return a status of PR_SUCCESS. Otherwise
  1038. * a value of PR_FAILURE. The reason for the failure may be re-
  1039. * trieved using PR_GetError().
  1040. *************************************************************************
  1041. */
  1042. NSPR_API(PRStatus) PR_MkDir(const char *name, PRIntn mode);
  1043. /*
  1044. *************************************************************************
  1045. * FUNCTION: PR_MakeDir
  1046. * DESCRIPTION:
  1047. * Create a new directory with the given name and access mode.
  1048. * PR_MakeDir has the same prototype as PR_MkDir but implements
  1049. * the specified access mode where possible.
  1050. *************************************************************************
  1051. */
  1052. NSPR_API(PRStatus) PR_MakeDir(const char *name, PRIntn mode);
  1053. /*
  1054. *************************************************************************
  1055. * FUNCTION: PR_RmDir
  1056. * DESCRIPTION:
  1057. * Remove a directory by the given name.
  1058. * INPUTS:
  1059. * const char *name
  1060. * The name of the directory to be removed. All the path components
  1061. * must already exist. Only the leaf component will be removed.
  1062. * OUTPUTS:
  1063. * None
  1064. * RETURN: PRStatus
  1065. * If successful, will return a status of PR_SUCCESS. Otherwise
  1066. * a value of PR_FAILURE. The reason for the failure may be re-
  1067. * trieved using PR_GetError().
  1068. **************************************************************************
  1069. */
  1070. NSPR_API(PRStatus) PR_RmDir(const char *name);
  1071. /*
  1072. *************************************************************************
  1073. * FUNCTION: PR_NewUDPSocket
  1074. * DESCRIPTION:
  1075. * Create a new UDP socket.
  1076. * INPUTS:
  1077. * None
  1078. * OUTPUTS:
  1079. * None
  1080. * RETURN: PRFileDesc*
  1081. * Upon successful completion, PR_NewUDPSocket returns a pointer
  1082. * to the PRFileDesc created for the newly opened UDP socket.
  1083. * Returns a NULL pointer if the creation of a new UDP socket failed.
  1084. *
  1085. **************************************************************************
  1086. */
  1087. NSPR_API(PRFileDesc*) PR_NewUDPSocket(void);
  1088. /*
  1089. *************************************************************************
  1090. * FUNCTION: PR_NewTCPSocket
  1091. * DESCRIPTION:
  1092. * Create a new TCP socket.
  1093. * INPUTS:
  1094. * None
  1095. * OUTPUTS:
  1096. * None
  1097. * RETURN: PRFileDesc*
  1098. * Upon successful completion, PR_NewTCPSocket returns a pointer
  1099. * to the PRFileDesc created for the newly opened TCP socket.
  1100. * Returns a NULL pointer if the creation of a new TCP socket failed.
  1101. *
  1102. **************************************************************************
  1103. */
  1104. NSPR_API(PRFileDesc*) PR_NewTCPSocket(void);
  1105. /*
  1106. *************************************************************************
  1107. * FUNCTION: PR_OpenUDPSocket
  1108. * DESCRIPTION:
  1109. * Create a new UDP socket of the specified address family.
  1110. * INPUTS:
  1111. * PRIntn af
  1112. * Address family
  1113. * OUTPUTS:
  1114. * None
  1115. * RETURN: PRFileDesc*
  1116. * Upon successful completion, PR_OpenUDPSocket returns a pointer
  1117. * to the PRFileDesc created for the newly opened UDP socket.
  1118. * Returns a NULL pointer if the creation of a new UDP socket failed.
  1119. *
  1120. **************************************************************************
  1121. */
  1122. NSPR_API(PRFileDesc*) PR_OpenUDPSocket(PRIntn af);
  1123. /*
  1124. *************************************************************************
  1125. * FUNCTION: PR_OpenTCPSocket
  1126. * DESCRIPTION:
  1127. * Create a new TCP socket of the specified address family.
  1128. * INPUTS:
  1129. * PRIntn af
  1130. * Address family
  1131. * OUTPUTS:
  1132. * None
  1133. * RETURN: PRFileDesc*
  1134. * Upon successful completion, PR_NewTCPSocket returns a pointer
  1135. * to the PRFileDesc created for the newly opened TCP socket.
  1136. * Returns a NULL pointer if the creation of a new TCP socket failed.
  1137. *
  1138. **************************************************************************
  1139. */
  1140. NSPR_API(PRFileDesc*) PR_OpenTCPSocket(PRIntn af);
  1141. /*
  1142. *************************************************************************
  1143. * FUNCTION: PR_Connect
  1144. * DESCRIPTION:
  1145. * Initiate a connection on a socket.
  1146. * INPUTS:
  1147. * PRFileDesc *fd
  1148. * Points to a PRFileDesc object representing a socket
  1149. * PRNetAddr *addr
  1150. * Specifies the address of the socket in its own communication
  1151. * space.
  1152. * PRIntervalTime timeout
  1153. * Time limit for completion of the connect operation.
  1154. * OUTPUTS:
  1155. * None
  1156. * RETURN: PRStatus
  1157. * Upon successful completion of connection initiation, PR_Connect
  1158. * returns PR_SUCCESS. Otherwise, it returns PR_FAILURE. Further
  1159. * failure information can be obtained by calling PR_GetError().
  1160. **************************************************************************
  1161. */
  1162. NSPR_API(PRStatus) PR_Connect(
  1163. PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout);
  1164. /*
  1165. *************************************************************************
  1166. * FUNCTION: PR_ConnectContinue
  1167. * DESCRIPTION:
  1168. * Continue a nonblocking connect. After a nonblocking connect
  1169. * is initiated with PR_Connect() (which fails with
  1170. * PR_IN_PROGRESS_ERROR), one should call PR_Poll() on the socket,
  1171. * with the in_flags PR_POLL_WRITE | PR_POLL_EXCEPT. When
  1172. * PR_Poll() returns, one calls PR_ConnectContinue() on the
  1173. * socket to determine whether the nonblocking connect has
  1174. * completed or is still in progress. Repeat the PR_Poll(),
  1175. * PR_ConnectContinue() sequence until the nonblocking connect
  1176. * has completed.
  1177. * INPUTS:
  1178. * PRFileDesc *fd
  1179. * the file descriptor representing a socket
  1180. * PRInt16 out_flags
  1181. * the out_flags f…

Large files files are truncated, but you can click here to view the full file