145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** 245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \file libyasm/file.h 345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \brief YASM file helpers. 445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \license 645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Copyright (C) 2001-2007 Peter Johnson 745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Redistribution and use in source and binary forms, with or without 945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * modification, are permitted provided that the following conditions 1045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * are met: 1145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * - Redistributions of source code must retain the above copyright 1245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * notice, this list of conditions and the following disclaimer. 1345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * - Redistributions in binary form must reproduce the above copyright 1445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * notice, this list of conditions and the following disclaimer in the 1545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * documentation and/or other materials provided with the distribution. 1645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 1745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' 1845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE 2145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * POSSIBILITY OF SUCH DAMAGE. 2845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \endlicense 2945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 3045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef YASM_FILE_H 3145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_FILE_H 3245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef YASM_LIB_DECL 3445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_LIB_DECL 3545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif 3645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Re2c scanner state. */ 3845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_scanner { 3945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned char *bot; /**< Bottom of scan buffer */ 4045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned char *tok; /**< Start of token */ 4145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned char *ptr; /**< Scan marker */ 4245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned char *cur; /**< Cursor (1 past end of token) */ 4345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned char *lim; /**< Limit of good data */ 4445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned char *top; /**< Top of scan buffer */ 4545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned char *eof; /**< End of file */ 4645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} yasm_scanner; 4745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Initialize scanner state. 4945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param scanner Re2c scanner state 5045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 5145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 5245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_scanner_initialize(yasm_scanner *scanner); 5345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 5445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Frees any memory used by scanner state; does not free state itself. 5545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param scanner Re2c scanner state 5645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 5745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 5845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_scanner_delete(yasm_scanner *scanner); 5945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 6045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Fill a scanner state structure with data coming from an input function. 6145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param scanner Re2c scanner state 6245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param cursor Re2c scan cursor 6345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param input_func Input function to read data; takes buffer and maximum 6445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * number of bytes, returns number of bytes read. 6545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param input_func_data Data to pass as the first parameter to input_func 6645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return 1 if this was the first time this function was called on this 6745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * scanner state, 0 otherwise. 6845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 6945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 7045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint yasm_fill_helper 7145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (yasm_scanner *scanner, unsigned char **cursor, 7245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org size_t (*input_func) (void *d, unsigned char *buf, size_t max), 7345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org void *input_func_data); 7445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 7545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Unescape a string with C-style escapes. Handles b, f, n, r, t, and hex 7645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * and octal escapes. String is updated in-place. 7745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Edge cases: 7845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * - hex escapes: reads as many hex digits as possible, takes last 2 as value. 7945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * - oct escapes: takes up to 3 digits 0-9 and scales appropriately, with 8045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * warning. 8145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param str C-style string (updated in place) 8245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param len length of string (updated with new length) 8345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 8445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 8545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_unescape_cstring(unsigned char *str, size_t *len); 8645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 8745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Split a UNIX pathname into head (directory) and tail (base filename) 8845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * portions. 8945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \internal 9045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param path pathname 9145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param tail (returned) base filename 9245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Length of head (directory). 9345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 9445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 9545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgsize_t yasm__splitpath_unix(const char *path, /*@out@*/ const char **tail); 9645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 9745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Split a Windows pathname into head (directory) and tail (base filename) 9845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * portions. 9945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \internal 10045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param path pathname 10145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param tail (returned) base filename 10245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Length of head (directory). 10345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 10445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 10545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgsize_t yasm__splitpath_win(const char *path, /*@out@*/ const char **tail); 10645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 10745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Split a pathname into head (directory) and tail (base filename) portions. 10845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Unless otherwise defined, defaults to yasm__splitpath_unix(). 10945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \internal 11045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param path pathname 11145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param tail (returned) base filename 11245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Length of head (directory). 11345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 11445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef yasm__splitpath 11545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org# if defined (_WIN32) || defined (WIN32) || defined (__MSDOS__) || \ 11645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org defined (__DJGPP__) || defined (__OS2__) 11745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org# define yasm__splitpath(path, tail) yasm__splitpath_win(path, tail) 11845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org# else 11945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org# define yasm__splitpath(path, tail) yasm__splitpath_unix(path, tail) 12045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org# endif 12145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif 12245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 12345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Get the current working directory. 12445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \internal 12545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Current working directory pathname (newly allocated). 12645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 12745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 12845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@only@*/ char *yasm__getcwd(void); 12945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 13045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Convert a relative or absolute pathname into an absolute pathname. 13145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \internal 13245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param path pathname 13345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Absolute version of path (newly allocated). 13445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 13545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 13645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@only@*/ char *yasm__abspath(const char *path); 13745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 13845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Build a UNIX pathname that is equivalent to accessing the "to" pathname 13945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * when you're in the directory containing "from". Result is relative if both 14045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * from and to are relative. 14145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \internal 14245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param from from pathname 14345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param to to pathname 14445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Combined path (newly allocated). 14545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 14645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 14745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgchar *yasm__combpath_unix(const char *from, const char *to); 14845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 14945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Build a Windows pathname that is equivalent to accessing the "to" pathname 15045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * when you're in the directory containing "from". Result is relative if both 15145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * from and to are relative. 15245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \internal 15345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param from from pathname 15445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param to to pathname 15545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Combined path (newly allocated). 15645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 15745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 15845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgchar *yasm__combpath_win(const char *from, const char *to); 15945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 16045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Build a pathname that is equivalent to accessing the "to" pathname 16145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * when you're in the directory containing "from". Result is relative if both 16245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * from and to are relative. 16345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Unless otherwise defined, defaults to yasm__combpath_unix(). 16445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \internal 16545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param from from pathname 16645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param to to pathname 16745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Combined path (newly allocated). 16845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 16945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef yasm__combpath 17045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org# if defined (_WIN32) || defined (WIN32) || defined (__MSDOS__) || \ 17145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org defined (__DJGPP__) || defined (__OS2__) 17245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org# define yasm__combpath(from, to) yasm__combpath_win(from, to) 17345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org# else 17445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org# define yasm__combpath(from, to) yasm__combpath_unix(from, to) 17545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org# endif 17645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif 17745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 178a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org/** Recursively create tree of directories needed for pathname. 179a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org * \internal 180a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org * \param path pathname 181a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org * \param win handle windows paths 182a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org * \return Length of directory portion of pathname. 183a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org */ 184a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.orgYASM_LIB_DECL 185a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.orgsize_t yasm__createpath_common(const char *path, int win); 186a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org 187a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org/** Recursively create tree of directories needed for pathname. 188a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org * Unless otherwise defined, defaults to yasm__createpath_unix(). 189a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org * \internal 190a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org * \param path pathname 191a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org * \return Length of directory portion of pathname. 192a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org */ 193a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org#ifndef yasm__createpath 194a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org# if defined (_WIN32) || defined (WIN32) || defined (__MSDOS__) || \ 195a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org defined (__DJGPP__) || defined (__OS2__) 196a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org# define yasm__createpath(path) yasm__createpath_common(path, 1) 197a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org# else 198a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org# define yasm__createpath(path) yasm__createpath_common(path, 0) 199a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org# endif 200a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org#endif 201a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org 20245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Try to find and open an include file, searching through include paths. 20345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * First iname is looked for relative to the directory containing "from", then 20445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * it's looked for relative to each of the include paths. 20545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 20645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * All pathnames may be either absolute or relative; from, oname, and 20745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * include paths, if relative, are relative from the current working directory. 20845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 20945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * First match wins; the full pathname (newly allocated) to the opened file 21045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * is saved into oname, and the fopen'ed FILE * is returned. If not found, 21145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * NULL is returned. 21245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 21345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param iname file to include 21445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param from file doing the including 21545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param mode fopen mode string 21645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param oname full pathname of included file (may be relative). NULL 21745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * may be passed if this is unwanted. 21845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return fopen'ed include file, or NULL if not found. 21945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 22045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 22145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@null@*/ FILE *yasm_fopen_include 22245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (const char *iname, const char *from, const char *mode, 22345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*@null@*/ /*@out@*/ /*@only@*/ char **oname); 22445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 22545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Delete any stored include paths added by yasm_add_include_path(). 22645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 22745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 22845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_delete_include_paths(void); 22945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 23045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Iterate through include paths. 23145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org*/ 23245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 23345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgconst char * yasm_get_include_dir(void **iter); 23445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 23545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Add an include path for use by yasm_fopen_include(). 23645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * If path is relative, it is treated by yasm_fopen_include() as relative to 23745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * the current working directory. 23845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 23945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param path path to add 24045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 24145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 24245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_add_include_path(const char *path); 24345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 24445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Write an 8-bit value to a buffer, incrementing buffer pointer. 24545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Only works properly if ptr is an (unsigned char *). 24645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr buffer 24745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 8-bit value 24845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 24945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_WRITE_8(ptr, val) \ 25045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)++) = (unsigned char)((val) & 0xFF) 25145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 25245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Write a 16-bit value to a buffer in little endian, incrementing buffer 25345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * pointer. 25445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Only works properly if ptr is an (unsigned char *). 25545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr buffer 25645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 16-bit value 25745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 25845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_WRITE_16_L(ptr, val) \ 25945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org do { \ 26045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)++) = (unsigned char)((val) & 0xFF); \ 26145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)++) = (unsigned char)(((val) >> 8) & 0xFF); \ 26245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } while (0) 26345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 26445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Write a 32-bit value to a buffer in little endian, incrementing buffer 26545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * pointer. 26645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Only works properly if ptr is an (unsigned char *). 26745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr buffer 26845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 32-bit value 26945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 27045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_WRITE_32_L(ptr, val) \ 27145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org do { \ 27245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)++) = (unsigned char)((val) & 0xFF); \ 27345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)++) = (unsigned char)(((val) >> 8) & 0xFF); \ 27445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)++) = (unsigned char)(((val) >> 16) & 0xFF); \ 27545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)++) = (unsigned char)(((val) >> 24) & 0xFF); \ 27645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } while (0) 27745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 27845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Write a 16-bit value to a buffer in big endian, incrementing buffer 27945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * pointer. 28045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Only works properly if ptr is an (unsigned char *). 28145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr buffer 28245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 16-bit value 28345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 28445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_WRITE_16_B(ptr, val) \ 28545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org do { \ 28645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)++) = (unsigned char)(((val) >> 8) & 0xFF); \ 28745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)++) = (unsigned char)((val) & 0xFF); \ 28845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } while (0) 28945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 29045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Write a 32-bit value to a buffer in big endian, incrementing buffer 29145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * pointer. 29245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Only works properly if ptr is an (unsigned char *). 29345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr buffer 29445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 32-bit value 29545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 29645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_WRITE_32_B(ptr, val) \ 29745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org do { \ 29845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)++) = (unsigned char)(((val) >> 24) & 0xFF); \ 29945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)++) = (unsigned char)(((val) >> 16) & 0xFF); \ 30045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)++) = (unsigned char)(((val) >> 8) & 0xFF); \ 30145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)++) = (unsigned char)((val) & 0xFF); \ 30245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } while (0) 30345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 30445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 30545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Write an 8-bit value to a buffer. Does not increment buffer pointer. 30645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Only works properly if ptr is an (unsigned char *). 30745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr buffer 30845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 8-bit value 30945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 31045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_SAVE_8(ptr, val) \ 31145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *(ptr) = (unsigned char)((val) & 0xFF) 31245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 31345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Write a 16-bit value to a buffer in little endian. Does not increment 31445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * buffer pointer. 31545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Only works properly if ptr is an (unsigned char *). 31645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr buffer 31745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 16-bit value 31845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 31945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_SAVE_16_L(ptr, val) \ 32045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org do { \ 32145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *(ptr) = (unsigned char)((val) & 0xFF); \ 32245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)+1) = (unsigned char)(((val) >> 8) & 0xFF); \ 32345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } while (0) 32445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 32545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Write a 32-bit value to a buffer in little endian. Does not increment 32645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * buffer pointer. 32745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Only works properly if ptr is an (unsigned char *). 32845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr buffer 32945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 32-bit value 33045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 33145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_SAVE_32_L(ptr, val) \ 33245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org do { \ 33345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *(ptr) = (unsigned char)((val) & 0xFF); \ 33445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)+1) = (unsigned char)(((val) >> 8) & 0xFF); \ 33545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)+2) = (unsigned char)(((val) >> 16) & 0xFF); \ 33645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)+3) = (unsigned char)(((val) >> 24) & 0xFF); \ 33745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } while (0) 33845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 33945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Write a 16-bit value to a buffer in big endian. Does not increment buffer 34045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * pointer. 34145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Only works properly if ptr is an (unsigned char *). 34245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr buffer 34345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 16-bit value 34445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 34545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_SAVE_16_B(ptr, val) \ 34645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org do { \ 34745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *(ptr) = (unsigned char)(((val) >> 8) & 0xFF); \ 34845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)+1) = (unsigned char)((val) & 0xFF); \ 34945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } while (0) 35045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 35145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Write a 32-bit value to a buffer in big endian. Does not increment buffer 35245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * pointer. 35345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Only works properly if ptr is an (unsigned char *). 35445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr buffer 35545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 32-bit value 35645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 35745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_SAVE_32_B(ptr, val) \ 35845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org do { \ 35945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *(ptr) = (unsigned char)(((val) >> 24) & 0xFF); \ 36045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)+1) = (unsigned char)(((val) >> 16) & 0xFF); \ 36145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)+2) = (unsigned char)(((val) >> 8) & 0xFF); \ 36245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *((ptr)+3) = (unsigned char)((val) & 0xFF); \ 36345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } while (0) 36445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 36545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Direct-to-file version of YASM_SAVE_16_L(). 36645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Using the macro multiple times with a single fwrite() call will 36745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * probably be faster than calling this function many times. 36845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 16-bit value 36945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param f file 37045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return 1 if the write was successful, 0 if not (just like fwrite()). 37145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 37245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 37345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgsize_t yasm_fwrite_16_l(unsigned short val, FILE *f); 37445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 37545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Direct-to-file version of YASM_SAVE_32_L(). 37645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Using the macro multiple times with a single fwrite() call will 37745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * probably be faster than calling this function many times. 37845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 32-bit value 37945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param f file 38045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return 1 if the write was successful, 0 if not (just like fwrite()). 38145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 38245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 38345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgsize_t yasm_fwrite_32_l(unsigned long val, FILE *f); 38445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 38545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Direct-to-file version of YASM_SAVE_16_B(). 38645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Using the macro multiple times with a single fwrite() call will 38745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * probably be faster than calling this function many times. 38845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 16-bit value 38945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param f file 39045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return 1 if the write was successful, 0 if not (just like fwrite()). 39145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 39245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 39345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgsize_t yasm_fwrite_16_b(unsigned short val, FILE *f); 39445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 39545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Direct-to-file version of YASM_SAVE_32_B(). 39645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Using the macro multiple times with a single fwrite() call will 39745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * probably be faster than calling this function many times. 39845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 32-bit value 39945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param f file 40045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return 1 if the write was successful, 0 if not (just like fwrite()). 40145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 40245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 40345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgsize_t yasm_fwrite_32_b(unsigned long val, FILE *f); 40445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 40545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Read an 8-bit value from a buffer, incrementing buffer pointer. 40645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Only works properly if ptr is an (unsigned char *). 40745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr buffer 40845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 8-bit value 40945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 41045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_READ_8(val, ptr) \ 41145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) = *((ptr)++) & 0xFF 41245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 41345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Read a 16-bit value from a buffer in little endian, incrementing buffer 41445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * pointer. 41545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Only works properly if ptr is an (unsigned char *). 41645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr buffer 41745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 16-bit value 41845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 41945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_READ_16_L(val, ptr) \ 42045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org do { \ 42145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) = *((ptr)++) & 0xFF; \ 42245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) |= (*((ptr)++) & 0xFF) << 8; \ 42345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } while (0) 42445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 42545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Read a 32-bit value from a buffer in little endian, incrementing buffer 42645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * pointer. 42745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Only works properly if ptr is an (unsigned char *). 42845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr buffer 42945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 32-bit value 43045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 43145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_READ_32_L(val, ptr) \ 43245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org do { \ 43345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) = *((ptr)++) & 0xFF; \ 43445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) |= (*((ptr)++) & 0xFF) << 8; \ 43545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) |= (*((ptr)++) & 0xFF) << 16; \ 43645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) |= (*((ptr)++) & 0xFF) << 24; \ 43745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } while (0) 43845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 43945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Read a 16-bit value from a buffer in big endian, incrementing buffer 44045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * pointer. 44145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Only works properly if ptr is an (unsigned char *). 44245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr buffer 44345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 16-bit value 44445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 44545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_READ_16_B(val, ptr) \ 44645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org do { \ 44745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) = (*((ptr)++) & 0xFF) << 8; \ 44845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) |= *((ptr)++) & 0xFF; \ 44945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } while (0) 45045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 45145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Read a 32-bit value from a buffer in big endian, incrementing buffer 45245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * pointer. 45345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Only works properly if ptr is an (unsigned char *). 45445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr buffer 45545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 32-bit value 45645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 45745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_READ_32_B(val, ptr) \ 45845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org do { \ 45945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) = (*((ptr)++) & 0xFF) << 24; \ 46045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) |= (*((ptr)++) & 0xFF) << 16; \ 46145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) |= (*((ptr)++) & 0xFF) << 8; \ 46245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) |= *((ptr)++) & 0xFF; \ 46345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } while (0) 46445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 46545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Read an 8-bit value from a buffer. Does not increment buffer pointer. 46645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Only works properly if ptr is an (unsigned char *). 46745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr buffer 46845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 8-bit value 46945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 47045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_LOAD_8(val, ptr) \ 47145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) = *(ptr) & 0xFF 47245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 47345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Read a 16-bit value from a buffer in little endian. Does not increment 47445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * buffer pointer. 47545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Only works properly if ptr is an (unsigned char *). 47645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr buffer 47745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 16-bit value 47845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 47945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_LOAD_16_L(val, ptr) \ 48045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org do { \ 48145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) = *(ptr) & 0xFF; \ 48245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) |= (*((ptr)+1) & 0xFF) << 8; \ 48345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } while (0) 48445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 48545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Read a 32-bit value from a buffer in little endian. Does not increment 48645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * buffer pointer. 48745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Only works properly if ptr is an (unsigned char *). 48845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr buffer 48945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 32-bit value 49045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 49145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_LOAD_32_L(val, ptr) \ 49245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org do { \ 49345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) = (unsigned long)(*(ptr) & 0xFF); \ 49445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) |= (unsigned long)((*((ptr)+1) & 0xFF) << 8); \ 49545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) |= (unsigned long)((*((ptr)+2) & 0xFF) << 16); \ 49645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) |= (unsigned long)((*((ptr)+3) & 0xFF) << 24); \ 49745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } while (0) 49845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 49945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Read a 16-bit value from a buffer in big endian. Does not increment buffer 50045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * pointer. 50145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Only works properly if ptr is an (unsigned char *). 50245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr buffer 50345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 16-bit value 50445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 50545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_LOAD_16_B(val, ptr) \ 50645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org do { \ 50745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) = (*(ptr) & 0xFF) << 8; \ 50845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) |= *((ptr)+1) & 0xFF; \ 50945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } while (0) 51045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 51145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Read a 32-bit value from a buffer in big endian. Does not increment buffer 51245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * pointer. 51345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Only works properly if ptr is an (unsigned char *). 51445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ptr buffer 51545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val 32-bit value 51645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 51745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_LOAD_32_B(val, ptr) \ 51845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org do { \ 51945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) = (unsigned long)((*(ptr) & 0xFF) << 24); \ 52045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) |= (unsigned long)((*((ptr)+1) & 0xFF) << 16); \ 52145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) |= (unsigned long)((*((ptr)+2) & 0xFF) << 8); \ 52245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (val) |= (unsigned long)(*((ptr)+3) & 0xFF); \ 52345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } while (0) 52445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 52545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif 526