Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Write doc for MSG_file function.
[simgrid.git] / src / msg / msg_io.c
1 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012. The SimGrid Team.
2  * All rights reserved.                                                                  */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package.              */
6
7 #include "msg_private.h"
8
9 /** @addtogroup m_file_management
10  *     \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="File" --> \endhtmlonly
11  * (#m_file_t) and the functions for managing it.
12  *
13  *  \see m_file_t
14  */
15
16 /********************************* File **************************************/
17
18 /** \ingroup m_file_management
19  * \brief Read elements of a file
20  *
21  * \param storage is the name where find the stream
22  * \param ptr buffer to where the data is copied
23  * \param size of each element
24  * \param nmemb is the number of elements of data to read
25  * \param stream to read
26  * \return the number of items successfully read
27  */
28 size_t MSG_file_read(const char* storage, void* ptr, size_t size, size_t nmemb,  m_file_t stream)
29 {
30   return simcall_file_read(storage, ptr, size, nmemb, (smx_file_t)stream);
31 }
32
33 /** \ingroup m_file_management
34  * \brief Write elements into a file
35  *
36  * \param storage is the name where find the stream
37  * \param ptr buffer from where the data is copied
38  * \param size of each element
39  * \param nmemb is the number of elements of data to write
40  * \param stream to write
41  * \return the number of items successfully write
42  */
43 size_t MSG_file_write(const char* storage, const void* ptr, size_t size, size_t nmemb, m_file_t stream)
44 {
45   return simcall_file_write(storage, ptr, size, nmemb, (smx_file_t)stream);
46 }
47
48 /** \ingroup m_file_management
49  * \brief Opens the file whose name is the string pointed to by path
50  *
51  * \param storage is the name where find the file to open
52  * \param path is the file location on the storage
53  * \param mode points to a string beginning with one of the following sequences (Additional characters may follow these sequences.):
54  *      r      Open text file for reading.  The stream is positioned at the beginning of the file.
55  *      r+     Open for reading and writing.  The stream is positioned at the beginning of the file.
56  *      w      Truncate file to zero length or create text file for writing.  The stream is positioned at the beginning of the file.
57  *      w+     Open for reading and writing.  The file is created if it does not exist, otherwise it is truncated.  The stream is positioned at the beginā€
58  *             ning of the file.
59  *      a      Open for appending (writing at end of file).  The file is created if it does not exist.  The stream is positioned at the end of the file.
60  *      a+     Open for reading and appending (writing at end of file).  The file is created if it does not exist.  The initial file position for  reading
61  *             is at the beginning of the file, but output is always appended to the end of the file.
62  *
63  * \return A m_file_t associated to the file
64  */
65 m_file_t MSG_file_open(const char* storage, const char* path, const char* mode)
66 {
67   return (m_file_t) simcall_file_open(storage, path, mode);
68 }
69
70 /** \ingroup m_file_management
71  * \brief Close the file
72  *
73  * \param storage is the name where find the stream
74  * \param fp is the file to close
75  * \return 0 on success or 1 on error
76  */
77 int MSG_file_close(const char* storage, m_file_t fp)
78 {
79   return simcall_file_close(storage, (smx_file_t)fp);
80 }
81
82 /** \ingroup m_file_management
83  * \brief Stats the file pointed by fd
84  *
85  * \param storage is the name where find the stream
86  * \param fd is the file descriptor
87  * \param buf is the return structure with informations
88  * \return 0 on success or 1 on error
89  */
90 int MSG_file_stat(const char* storage, int fd, void* buf)
91 {
92   return simcall_file_stat(storage, fd, buf);
93 }