• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2019, The Linux Foundation. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *    * Redistributions of source code must retain the above copyright
8  *      notice, this list of conditions and the following disclaimer.
9  *    * Redistributions in binary form must reproduce the above
10  *      copyright notice, this list of conditions and the following
11  *      disclaimer in the documentation and/or other materials provided
12  *      with the distribution.
13  *    * Neither the name of The Linux Foundation nor the names of its
14  *      contributors may be used to endorse or promote products derived
15  *      from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef _APPS_STD_H
31 #define _APPS_STD_H
32 #include "AEEStdDef.h"
33 #ifndef __QAIC_HEADER
34 #define __QAIC_HEADER(ff) ff
35 #endif //__QAIC_HEADER
36 
37 #ifndef __QAIC_HEADER_EXPORT
38 #define __QAIC_HEADER_EXPORT
39 #endif // __QAIC_HEADER_EXPORT
40 
41 #ifndef __QAIC_HEADER_ATTRIBUTE
42 #define __QAIC_HEADER_ATTRIBUTE
43 #endif // __QAIC_HEADER_ATTRIBUTE
44 
45 #ifndef __QAIC_IMPL
46 #define __QAIC_IMPL(ff) ff
47 #endif //__QAIC_IMPL
48 
49 #ifndef __QAIC_IMPL_EXPORT
50 #define __QAIC_IMPL_EXPORT
51 #endif // __QAIC_IMPL_EXPORT
52 
53 #ifndef __QAIC_IMPL_ATTRIBUTE
54 #define __QAIC_IMPL_ATTRIBUTE
55 #endif // __QAIC_IMPL_ATTRIBUTE
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 #if !defined(__QAIC_STRING1_OBJECT_DEFINED__) && !defined(__STRING1_OBJECT__)
60 #define __QAIC_STRING1_OBJECT_DEFINED__
61 #define __STRING1_OBJECT__
62 typedef struct _cstring1_s {
63    char* data;
64    int dataLen;
65 } _cstring1_t;
66 
67 #endif /* __QAIC_STRING1_OBJECT_DEFINED__ */
68 /**
69     * standard library functions remoted from the apps to the dsp
70     */
71 typedef int apps_std_FILE;
72 enum apps_std_SEEK {
73    APPS_STD_SEEK_SET,
74    APPS_STD_SEEK_CUR,
75    APPS_STD_SEEK_END,
76    _32BIT_PLACEHOLDER_apps_std_SEEK = 0x7fffffff
77 };
78 typedef enum apps_std_SEEK apps_std_SEEK;
79 typedef struct apps_std_DIR apps_std_DIR;
80 struct apps_std_DIR {
81    uint64 handle;
82 };
83 typedef struct apps_std_DIRENT apps_std_DIRENT;
84 struct apps_std_DIRENT {
85    int ino;
86    char name[255];
87 };
88 typedef struct apps_std_STAT apps_std_STAT;
89 struct apps_std_STAT {
90    uint64 tsz;
91    uint64 dev;
92    uint64 ino;
93    uint32 mode;
94    uint32 nlink;
95    uint64 rdev;
96    uint64 size;
97    int64 atime;
98    int64 atimensec;
99    int64 mtime;
100    int64 mtimensec;
101    int64 ctime;
102    int64 ctimensec;
103 };
104 /**
105        * @retval, if operation fails errno is returned
106        */
107 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fopen)(const char* name, const char* mode, apps_std_FILE* psout) __QAIC_HEADER_ATTRIBUTE;
108 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_freopen)(apps_std_FILE sin, const char* name, const char* mode, apps_std_FILE* psout) __QAIC_HEADER_ATTRIBUTE;
109 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fflush)(apps_std_FILE sin) __QAIC_HEADER_ATTRIBUTE;
110 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fclose)(apps_std_FILE sin) __QAIC_HEADER_ATTRIBUTE;
111 /**
112        * @param,  bEOF, if read or write bytes <= bufLen bytes then feof() is called
113        *          and the result is returned in bEOF, otherwise bEOF is set to 0.
114        * @retval, if read or write return 0 for non zero length buffers, ferror is checked
115        *          and a non zero value is returned in case of error with no rout parameters
116        */
117 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fread)(apps_std_FILE sin, byte* buf, int bufLen, int* bytesRead, int* bEOF) __QAIC_HEADER_ATTRIBUTE;
118 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fwrite)(apps_std_FILE sin, const byte* buf, int bufLen, int* bytesWritten, int* bEOF) __QAIC_HEADER_ATTRIBUTE;
119 /**
120        * @param, pos, this buffer is filled up to MIN(posLen, sizeof(fpos_t))
121        * @param, posLenReq, returns sizeof(fpos_t)
122        * @retval, if operation fails errno is returned
123        */
124 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fgetpos)(apps_std_FILE sin, byte* pos, int posLen, int* posLenReq) __QAIC_HEADER_ATTRIBUTE;
125 /**
126        * @param, if size of pos doesn't match the system size an error is returned.
127        *         fgetpos can be used to query the size of fpos_t
128        * @retval, if operation fails errno is returned
129        */
130 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fsetpos)(apps_std_FILE sin, const byte* pos, int posLen) __QAIC_HEADER_ATTRIBUTE;
131 /**
132        * @retval, if operation fails errno is returned
133        */
134 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_ftell)(apps_std_FILE sin, int* pos) __QAIC_HEADER_ATTRIBUTE;
135 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fseek)(apps_std_FILE sin, int offset, apps_std_SEEK whence) __QAIC_HEADER_ATTRIBUTE;
136 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_flen)(apps_std_FILE sin, uint64* len) __QAIC_HEADER_ATTRIBUTE;
137 /**
138        * @retval, only fails if transport fails
139        */
140 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_rewind)(apps_std_FILE sin) __QAIC_HEADER_ATTRIBUTE;
141 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_feof)(apps_std_FILE sin, int* bEOF) __QAIC_HEADER_ATTRIBUTE;
142 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_ferror)(apps_std_FILE sin, int* err) __QAIC_HEADER_ATTRIBUTE;
143 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_clearerr)(apps_std_FILE sin) __QAIC_HEADER_ATTRIBUTE;
144 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_print_string)(const char* str) __QAIC_HEADER_ATTRIBUTE;
145 /**
146        * @param val, must contain space for NULL
147        * @param valLenReq, length required with NULL
148        * @retval, if fails errno is returned
149        */
150 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_getenv)(const char* name, char* val, int valLen, int* valLenReq) __QAIC_HEADER_ATTRIBUTE;
151 /**
152        * @retval, if fails errno is returned
153        */
154 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_setenv)(const char* name, const char* val, int override) __QAIC_HEADER_ATTRIBUTE;
155 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_unsetenv)(const char* name) __QAIC_HEADER_ATTRIBUTE;
156 /**
157        * This function will try to open a file given directories in envvarname separated by
158        * delim.
159        * so given environment variable FOO_PATH=/foo;/bar
160        *    fopen_wth_env("FOO_PATH", ";", "path/to/file", "rw", &out);
161        * will try to open /foo/path/to/file, /bar/path/to/file
162        * if the variable is unset, it will open the file directly
163        *
164        * @param envvarname, name of the environment variable containing the path
165        * @param delim, delimiator string, such as ";"
166        * @param name, name of the file
167        * @param mode, mode
168        * @param psout, output handle
169        * @retval, 0 on success errno or -1 on failure
170        */
171 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fopen_with_env)(const char* envvarname, const char* delim, const char* name, const char* mode, apps_std_FILE* psout) __QAIC_HEADER_ATTRIBUTE;
172 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fgets)(apps_std_FILE sin, byte* buf, int bufLen, int* bEOF) __QAIC_HEADER_ATTRIBUTE;
173 /**
174        * This method will return the paths that are searched when looking for a file.
175        *  The paths are defined by the environment variable (separated by delimiters)
176        *  that is passed to the method.
177        *
178        * @param envvarname, name of the environment variable containing the path
179        * @param delim, delimiator string, such as ";"
180        * @param name, name of the file
181        * @param paths, Search paths
182        * @param numPaths, Actual number of paths found
183        * @param maxPathLen, The max path length
184        * @retval, 0 on success errno or -1 on failure
185        *
186        */
187 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_get_search_paths_with_env)(const char* envvarname, const char* delim, _cstring1_t* paths, int pathsLen, uint32* numPaths, uint16* maxPathLen) __QAIC_HEADER_ATTRIBUTE;
188 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fileExists)(const char* path, boolean* exists) __QAIC_HEADER_ATTRIBUTE;
189 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fsync)(apps_std_FILE sin) __QAIC_HEADER_ATTRIBUTE;
190 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fremove)(const char* name) __QAIC_HEADER_ATTRIBUTE;
191 /**
192         * This function decrypts the file using the provided open file descriptor, closes the
193         * original descriptor and return a new file descriptor.
194         * @retval, if operation fails errno is returned
195         */
196 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fdopen_decrypt)(apps_std_FILE sin, apps_std_FILE* psout) __QAIC_HEADER_ATTRIBUTE;
197 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_opendir)(const char* name, apps_std_DIR* dir) __QAIC_HEADER_ATTRIBUTE;
198 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_closedir)(const apps_std_DIR* dir) __QAIC_HEADER_ATTRIBUTE;
199 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_readdir)(const apps_std_DIR* dir, apps_std_DIRENT* dirent, int* bEOF) __QAIC_HEADER_ATTRIBUTE;
200 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_mkdir)(const char* name, int mode) __QAIC_HEADER_ATTRIBUTE;
201 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_rmdir)(const char* name) __QAIC_HEADER_ATTRIBUTE;
202 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_stat)(const char* name, apps_std_STAT* stat) __QAIC_HEADER_ATTRIBUTE;
203 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_ftrunc)(apps_std_FILE sin, int offset) __QAIC_HEADER_ATTRIBUTE;
204 __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_frename)(const char* oldname, const char* newname) __QAIC_HEADER_ATTRIBUTE;
205 #ifdef __cplusplus
206 }
207 #endif
208 #endif //_APPS_STD_H
209