std_fixes.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // This file is part of BOINC.
  2. // http://boinc.berkeley.edu
  3. // Copyright (C) 2008 University of California
  4. //
  5. // BOINC is free software; you can redistribute it and/or modify it
  6. // under the terms of the GNU Lesser General Public License
  7. // as published by the Free Software Foundation,
  8. // either version 3 of the License, or (at your option) any later version.
  9. //
  10. // BOINC is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. // See the GNU Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public License
  16. // along with BOINC. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef BOINC_STD_FIXES_H
  18. #define BOINC_STD_FIXES_H
  19. #ifdef __cplusplus
  20. #ifndef CONFIG_TEST
  21. #ifndef HAVE_STD_MIN
  22. namespace std {
  23. #ifdef min
  24. #undef min
  25. #endif
  26. template <typename T>
  27. inline T min(const T &a, const T &b) {
  28. return ((a<b)?a:b);
  29. }
  30. }
  31. #endif /* HAVE_STD_MIN */
  32. #ifndef HAVE_STD_MAX
  33. namespace std {
  34. #ifdef max
  35. #undef max
  36. #endif
  37. template <typename T>
  38. inline T max(const T &a, const T &b) {
  39. return ((a>b)?a:b);
  40. }
  41. }
  42. #endif /* HAVE_STD_MAX */
  43. #ifndef HAVE_STD_TRANSFORM
  44. #include <algorithm>
  45. #include <iterator>
  46. namespace std {
  47. #ifdef transform
  48. #undef transform
  49. #endif
  50. template <typename i_iterator, typename o_iterator, typename OP>
  51. o_iterator transform(i_iterator first, i_iterator last, o_iterator res, OP op) {
  52. for (;first != last; first++) {
  53. *(res++)=op(*first);
  54. }
  55. return (res);
  56. }
  57. }
  58. #endif /* HAVE_STD_TRANSFORM */
  59. #endif /* CONFIG_TEST */
  60. #if defined(__cplusplus) && defined(LARGEFILE_BREAKS_CXX) && \
  61. (defined(_LARGE_FILES) || (_FILE_OFFSET_BITS==64)) \
  62. && !defined(_USING_FCGI_)
  63. #include <stdio.h>
  64. #include <fcntl.h>
  65. #undef fopen
  66. #undef freopen
  67. #undef tmpfile
  68. #undef fgetpos
  69. #undef fsetpos
  70. #undef fseeko
  71. #undef ftello
  72. #undef open
  73. #undef creat
  74. extern "C" {
  75. FILE *fopen(const char *, const char *);
  76. FILE *freopen(const char *, const char *, FILE *);
  77. FILE *tmpfile(void);
  78. int fgetpos(FILE *, fpos64_t *);
  79. int fsetpos(FILE *, const fpos64_t *);
  80. int fseeko(FILE *, const off64_t, int);
  81. off64_t ftello(FILE *);
  82. int open(const char *, int, mode_t mode=0);
  83. int creat(const char *, mode_t mode);
  84. }
  85. inline FILE *fopen(const char *path, const char *mode) { return fopen64(path,
  86. mode); }
  87. inline FILE *freopen(const char *path, const char *mode, FILE *file) { return
  88. freopen64(path,mode,file); }
  89. inline FILE *tmpfile(void) {return tmpfile64();}
  90. inline int fgetpos(FILE *file, fpos64_t *pos) { return fgetpos64(file,pos); }
  91. inline int fsetpos(FILE *file, const fpos64_t *pos) { return fsetpos64(file,pos); }
  92. inline int fseeko(FILE *file, const off64_t pos, int whence) {return fseeko64(file,pos,whence);}
  93. inline off64_t ftello(FILE *file) {return ftello64(file);}
  94. inline int open(const char *filename, int flags, mode_t mode) { return open64(filename,flags,mode); }
  95. inline int creat(const char *filename, mode_t mode) { return creat64(filename,mode); }
  96. #endif
  97. #endif /* __cplusplus */
  98. #endif // BOINC_STD_FIXES_H