2009-06-23 21:00:14 +00:00
|
|
|
/*
|
|
|
|
* Hamlib Interface - numeric locale wrapping helpers
|
|
|
|
* Copyright (c) 2009 by Stephane Fillod
|
|
|
|
*
|
|
|
|
*
|
2011-08-21 01:54:17 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2009-06-23 21:00:14 +00:00
|
|
|
*
|
2011-08-21 01:54:17 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2009-06-23 21:00:14 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2011-08-21 01:54:17 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2009-06-23 21:00:14 +00:00
|
|
|
*
|
2011-08-21 01:54:17 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-06-23 21:00:14 +00:00
|
|
|
* License along with this library; if not, write to the Free Software
|
2011-08-21 01:54:17 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2009-06-23 21:00:14 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _NUM_STDIO_H
|
|
|
|
#define _NUM_STDIO_H 1
|
|
|
|
|
|
|
|
#include <locale.h>
|
|
|
|
|
2011-08-21 01:54:17 +00:00
|
|
|
/*
|
|
|
|
* This header file is internal to Hamlib and its backends,
|
2009-06-23 21:00:14 +00:00
|
|
|
* thus not part of the API.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wrapper for sscanf to workaround some locales where the decimal
|
|
|
|
* separator (float, ...) is not the dot.
|
|
|
|
*/
|
|
|
|
#define num_sscanf(a...) \
|
2017-08-07 13:04:25 +00:00
|
|
|
({ int __ret; char *__savedlocale; \
|
|
|
|
__savedlocale = setlocale(LC_NUMERIC, NULL); \
|
|
|
|
setlocale(LC_NUMERIC, "C"); \
|
|
|
|
__ret = sscanf(a); \
|
|
|
|
setlocale(LC_NUMERIC, __savedlocale); \
|
|
|
|
__ret; \
|
|
|
|
})
|
2009-06-23 21:00:14 +00:00
|
|
|
|
2009-11-17 21:45:04 +00:00
|
|
|
#define num_sprintf(s, a...) \
|
2017-08-07 13:04:25 +00:00
|
|
|
({ int __ret; char *__savedlocale; \
|
|
|
|
__savedlocale = setlocale(LC_NUMERIC, NULL); \
|
|
|
|
setlocale(LC_NUMERIC, "C"); \
|
|
|
|
__ret = sprintf(s, a); \
|
|
|
|
setlocale(LC_NUMERIC, __savedlocale); \
|
|
|
|
__ret; \
|
|
|
|
})
|
2009-11-17 21:45:04 +00:00
|
|
|
|
|
|
|
#define num_snprintf(s, n, a...) \
|
2017-08-07 13:04:25 +00:00
|
|
|
({ int __ret; char *__savedlocale; \
|
|
|
|
__savedlocale = setlocale(LC_NUMERIC, NULL); \
|
|
|
|
setlocale(LC_NUMERIC, "C"); \
|
|
|
|
__ret = snprintf(s, n, a); \
|
|
|
|
setlocale(LC_NUMERIC, __savedlocale); \
|
|
|
|
__ret; \
|
|
|
|
})
|
2009-06-23 21:00:14 +00:00
|
|
|
|
2017-08-07 13:04:25 +00:00
|
|
|
#endif /* _NUM_STDIO_H */
|