physfs_byteorder.c
changeset 654 c0ae01de361d
parent 629 b01a59827192
child 695 73bfbbe645a8
equal deleted inserted replaced
653:89d56fcb2b40 654:c0ae01de361d
   102 PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 x) { return(x); }
   102 PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 x) { return(x); }
   103 PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 x) { return(x); }
   103 PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 x) { return(x); }
   104 #endif
   104 #endif
   105 
   105 
   106 
   106 
   107 int PHYSFS_readSLE16(PHYSFS_file *file, PHYSFS_sint16 *val)
   107 int PHYSFS_readSLE16(PHYSFS_File *file, PHYSFS_sint16 *val)
   108 {
   108 {
   109     PHYSFS_sint16 in;
   109     PHYSFS_sint16 in;
   110     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   110     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   111     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   111     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   112     *val = PHYSFS_swapSLE16(in);
   112     *val = PHYSFS_swapSLE16(in);
   113     return(1);
   113     return(1);
   114 } /* PHYSFS_readSLE16 */
   114 } /* PHYSFS_readSLE16 */
   115 
   115 
   116 
   116 
   117 int PHYSFS_readULE16(PHYSFS_file *file, PHYSFS_uint16 *val)
   117 int PHYSFS_readULE16(PHYSFS_File *file, PHYSFS_uint16 *val)
   118 {
   118 {
   119     PHYSFS_uint16 in;
   119     PHYSFS_uint16 in;
   120     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   120     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   121     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   121     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   122     *val = PHYSFS_swapULE16(in);
   122     *val = PHYSFS_swapULE16(in);
   123     return(1);
   123     return(1);
   124 } /* PHYSFS_readULE16 */
   124 } /* PHYSFS_readULE16 */
   125 
   125 
   126 
   126 
   127 int PHYSFS_readSBE16(PHYSFS_file *file, PHYSFS_sint16 *val)
   127 int PHYSFS_readSBE16(PHYSFS_File *file, PHYSFS_sint16 *val)
   128 {
   128 {
   129     PHYSFS_sint16 in;
   129     PHYSFS_sint16 in;
   130     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   130     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   131     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   131     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   132     *val = PHYSFS_swapSBE16(in);
   132     *val = PHYSFS_swapSBE16(in);
   133     return(1);
   133     return(1);
   134 } /* PHYSFS_readSBE16 */
   134 } /* PHYSFS_readSBE16 */
   135 
   135 
   136 
   136 
   137 int PHYSFS_readUBE16(PHYSFS_file *file, PHYSFS_uint16 *val)
   137 int PHYSFS_readUBE16(PHYSFS_File *file, PHYSFS_uint16 *val)
   138 {
   138 {
   139     PHYSFS_uint16 in;
   139     PHYSFS_uint16 in;
   140     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   140     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   141     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   141     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   142     *val = PHYSFS_swapUBE16(in);
   142     *val = PHYSFS_swapUBE16(in);
   143     return(1);
   143     return(1);
   144 } /* PHYSFS_readUBE16 */
   144 } /* PHYSFS_readUBE16 */
   145 
   145 
   146 
   146 
   147 int PHYSFS_readSLE32(PHYSFS_file *file, PHYSFS_sint32 *val)
   147 int PHYSFS_readSLE32(PHYSFS_File *file, PHYSFS_sint32 *val)
   148 {
   148 {
   149     PHYSFS_sint32 in;
   149     PHYSFS_sint32 in;
   150     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   150     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   151     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   151     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   152     *val = PHYSFS_swapSLE32(in);
   152     *val = PHYSFS_swapSLE32(in);
   153     return(1);
   153     return(1);
   154 } /* PHYSFS_readSLE32 */
   154 } /* PHYSFS_readSLE32 */
   155 
   155 
   156 
   156 
   157 int PHYSFS_readULE32(PHYSFS_file *file, PHYSFS_uint32 *val)
   157 int PHYSFS_readULE32(PHYSFS_File *file, PHYSFS_uint32 *val)
   158 {
   158 {
   159     PHYSFS_uint32 in;
   159     PHYSFS_uint32 in;
   160     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   160     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   161     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   161     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   162     *val = PHYSFS_swapULE32(in);
   162     *val = PHYSFS_swapULE32(in);
   163     return(1);
   163     return(1);
   164 } /* PHYSFS_readULE32 */
   164 } /* PHYSFS_readULE32 */
   165 
   165 
   166 
   166 
   167 int PHYSFS_readSBE32(PHYSFS_file *file, PHYSFS_sint32 *val)
   167 int PHYSFS_readSBE32(PHYSFS_File *file, PHYSFS_sint32 *val)
   168 {
   168 {
   169     PHYSFS_sint32 in;
   169     PHYSFS_sint32 in;
   170     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   170     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   171     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   171     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   172     *val = PHYSFS_swapSBE32(in);
   172     *val = PHYSFS_swapSBE32(in);
   173     return(1);
   173     return(1);
   174 } /* PHYSFS_readSBE32 */
   174 } /* PHYSFS_readSBE32 */
   175 
   175 
   176 
   176 
   177 int PHYSFS_readUBE32(PHYSFS_file *file, PHYSFS_uint32 *val)
   177 int PHYSFS_readUBE32(PHYSFS_File *file, PHYSFS_uint32 *val)
   178 {
   178 {
   179     PHYSFS_uint32 in;
   179     PHYSFS_uint32 in;
   180     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   180     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   181     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   181     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   182     *val = PHYSFS_swapUBE32(in);
   182     *val = PHYSFS_swapUBE32(in);
   183     return(1);
   183     return(1);
   184 } /* PHYSFS_readUBE32 */
   184 } /* PHYSFS_readUBE32 */
   185 
   185 
   186 
   186 
   187 int PHYSFS_readSLE64(PHYSFS_file *file, PHYSFS_sint64 *val)
   187 int PHYSFS_readSLE64(PHYSFS_File *file, PHYSFS_sint64 *val)
   188 {
   188 {
   189     PHYSFS_sint64 in;
   189     PHYSFS_sint64 in;
   190     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   190     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   191     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   191     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   192     *val = PHYSFS_swapSLE64(in);
   192     *val = PHYSFS_swapSLE64(in);
   193     return(1);
   193     return(1);
   194 } /* PHYSFS_readSLE64 */
   194 } /* PHYSFS_readSLE64 */
   195 
   195 
   196 
   196 
   197 int PHYSFS_readULE64(PHYSFS_file *file, PHYSFS_uint64 *val)
   197 int PHYSFS_readULE64(PHYSFS_File *file, PHYSFS_uint64 *val)
   198 {
   198 {
   199     PHYSFS_uint64 in;
   199     PHYSFS_uint64 in;
   200     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   200     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   201     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   201     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   202     *val = PHYSFS_swapULE64(in);
   202     *val = PHYSFS_swapULE64(in);
   203     return(1);
   203     return(1);
   204 } /* PHYSFS_readULE64 */
   204 } /* PHYSFS_readULE64 */
   205 
   205 
   206 
   206 
   207 int PHYSFS_readSBE64(PHYSFS_file *file, PHYSFS_sint64 *val)
   207 int PHYSFS_readSBE64(PHYSFS_File *file, PHYSFS_sint64 *val)
   208 {
   208 {
   209     PHYSFS_sint64 in;
   209     PHYSFS_sint64 in;
   210     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   210     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   211     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   211     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   212     *val = PHYSFS_swapSBE64(in);
   212     *val = PHYSFS_swapSBE64(in);
   213     return(1);
   213     return(1);
   214 } /* PHYSFS_readSBE64 */
   214 } /* PHYSFS_readSBE64 */
   215 
   215 
   216 
   216 
   217 int PHYSFS_readUBE64(PHYSFS_file *file, PHYSFS_uint64 *val)
   217 int PHYSFS_readUBE64(PHYSFS_File *file, PHYSFS_uint64 *val)
   218 {
   218 {
   219     PHYSFS_uint64 in;
   219     PHYSFS_uint64 in;
   220     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   220     BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0);
   221     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   221     BAIL_IF_MACRO(PHYSFS_read(file, &in, sizeof (in), 1) != 1, NULL, 0);
   222     *val = PHYSFS_swapUBE64(in);
   222     *val = PHYSFS_swapUBE64(in);
   223     return(1);
   223     return(1);
   224 } /* PHYSFS_readUBE64 */
   224 } /* PHYSFS_readUBE64 */
   225 
   225 
   226 
   226 
   227 
   227 
   228 int PHYSFS_writeSLE16(PHYSFS_file *file, PHYSFS_sint16 val)
   228 int PHYSFS_writeSLE16(PHYSFS_File *file, PHYSFS_sint16 val)
   229 {
   229 {
   230     PHYSFS_sint16 out = PHYSFS_swapSLE16(val);
   230     PHYSFS_sint16 out = PHYSFS_swapSLE16(val);
   231     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   231     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   232     return(1);
   232     return(1);
   233 } /* PHYSFS_writeSLE16 */
   233 } /* PHYSFS_writeSLE16 */
   234 
   234 
   235 
   235 
   236 int PHYSFS_writeULE16(PHYSFS_file *file, PHYSFS_uint16 val)
   236 int PHYSFS_writeULE16(PHYSFS_File *file, PHYSFS_uint16 val)
   237 {
   237 {
   238     PHYSFS_uint16 out = PHYSFS_swapULE16(val);
   238     PHYSFS_uint16 out = PHYSFS_swapULE16(val);
   239     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   239     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   240     return(1);
   240     return(1);
   241 } /* PHYSFS_writeULE16 */
   241 } /* PHYSFS_writeULE16 */
   242 
   242 
   243 
   243 
   244 int PHYSFS_writeSBE16(PHYSFS_file *file, PHYSFS_sint16 val)
   244 int PHYSFS_writeSBE16(PHYSFS_File *file, PHYSFS_sint16 val)
   245 {
   245 {
   246     PHYSFS_sint16 out = PHYSFS_swapSBE16(val);
   246     PHYSFS_sint16 out = PHYSFS_swapSBE16(val);
   247     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   247     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   248     return(1);
   248     return(1);
   249 } /* PHYSFS_writeSBE16 */
   249 } /* PHYSFS_writeSBE16 */
   250 
   250 
   251 
   251 
   252 int PHYSFS_writeUBE16(PHYSFS_file *file, PHYSFS_uint16 val)
   252 int PHYSFS_writeUBE16(PHYSFS_File *file, PHYSFS_uint16 val)
   253 {
   253 {
   254     PHYSFS_uint16 out = PHYSFS_swapUBE16(val);
   254     PHYSFS_uint16 out = PHYSFS_swapUBE16(val);
   255     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   255     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   256     return(1);
   256     return(1);
   257 } /* PHYSFS_writeUBE16 */
   257 } /* PHYSFS_writeUBE16 */
   258 
   258 
   259 
   259 
   260 int PHYSFS_writeSLE32(PHYSFS_file *file, PHYSFS_sint32 val)
   260 int PHYSFS_writeSLE32(PHYSFS_File *file, PHYSFS_sint32 val)
   261 {
   261 {
   262     PHYSFS_sint32 out = PHYSFS_swapSLE32(val);
   262     PHYSFS_sint32 out = PHYSFS_swapSLE32(val);
   263     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   263     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   264     return(1);
   264     return(1);
   265 } /* PHYSFS_writeSLE32 */
   265 } /* PHYSFS_writeSLE32 */
   266 
   266 
   267 
   267 
   268 int PHYSFS_writeULE32(PHYSFS_file *file, PHYSFS_uint32 val)
   268 int PHYSFS_writeULE32(PHYSFS_File *file, PHYSFS_uint32 val)
   269 {
   269 {
   270     PHYSFS_uint32 out = PHYSFS_swapULE32(val);
   270     PHYSFS_uint32 out = PHYSFS_swapULE32(val);
   271     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   271     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   272     return(1);
   272     return(1);
   273 } /* PHYSFS_writeULE32 */
   273 } /* PHYSFS_writeULE32 */
   274 
   274 
   275 
   275 
   276 int PHYSFS_writeSBE32(PHYSFS_file *file, PHYSFS_sint32 val)
   276 int PHYSFS_writeSBE32(PHYSFS_File *file, PHYSFS_sint32 val)
   277 {
   277 {
   278     PHYSFS_sint32 out = PHYSFS_swapSBE32(val);
   278     PHYSFS_sint32 out = PHYSFS_swapSBE32(val);
   279     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   279     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   280     return(1);
   280     return(1);
   281 } /* PHYSFS_writeSBE32 */
   281 } /* PHYSFS_writeSBE32 */
   282 
   282 
   283 
   283 
   284 int PHYSFS_writeUBE32(PHYSFS_file *file, PHYSFS_uint32 val)
   284 int PHYSFS_writeUBE32(PHYSFS_File *file, PHYSFS_uint32 val)
   285 {
   285 {
   286     PHYSFS_uint32 out = PHYSFS_swapUBE32(val);
   286     PHYSFS_uint32 out = PHYSFS_swapUBE32(val);
   287     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   287     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   288     return(1);
   288     return(1);
   289 } /* PHYSFS_writeUBE32 */
   289 } /* PHYSFS_writeUBE32 */
   290 
   290 
   291 
   291 
   292 int PHYSFS_writeSLE64(PHYSFS_file *file, PHYSFS_sint64 val)
   292 int PHYSFS_writeSLE64(PHYSFS_File *file, PHYSFS_sint64 val)
   293 {
   293 {
   294     PHYSFS_sint64 out = PHYSFS_swapSLE64(val);
   294     PHYSFS_sint64 out = PHYSFS_swapSLE64(val);
   295     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   295     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   296     return(1);
   296     return(1);
   297 } /* PHYSFS_writeSLE64 */
   297 } /* PHYSFS_writeSLE64 */
   298 
   298 
   299 
   299 
   300 int PHYSFS_writeULE64(PHYSFS_file *file, PHYSFS_uint64 val)
   300 int PHYSFS_writeULE64(PHYSFS_File *file, PHYSFS_uint64 val)
   301 {
   301 {
   302     PHYSFS_uint64 out = PHYSFS_swapULE64(val);
   302     PHYSFS_uint64 out = PHYSFS_swapULE64(val);
   303     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   303     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   304     return(1);
   304     return(1);
   305 } /* PHYSFS_writeULE64 */
   305 } /* PHYSFS_writeULE64 */
   306 
   306 
   307 
   307 
   308 int PHYSFS_writeSBE64(PHYSFS_file *file, PHYSFS_sint64 val)
   308 int PHYSFS_writeSBE64(PHYSFS_File *file, PHYSFS_sint64 val)
   309 {
   309 {
   310     PHYSFS_sint64 out = PHYSFS_swapSBE64(val);
   310     PHYSFS_sint64 out = PHYSFS_swapSBE64(val);
   311     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   311     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   312     return(1);
   312     return(1);
   313 } /* PHYSFS_writeSBE64 */
   313 } /* PHYSFS_writeSBE64 */
   314 
   314 
   315 
   315 
   316 int PHYSFS_writeUBE64(PHYSFS_file *file, PHYSFS_uint64 val)
   316 int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val)
   317 {
   317 {
   318     PHYSFS_uint64 out = PHYSFS_swapUBE64(val);
   318     PHYSFS_uint64 out = PHYSFS_swapUBE64(val);
   319     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   319     BAIL_IF_MACRO(PHYSFS_write(file, &out, sizeof (out), 1) != 1, NULL, 0);
   320     return(1);
   320     return(1);
   321 } /* PHYSFS_writeUBE64 */
   321 } /* PHYSFS_writeUBE64 */