syscall.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef NATIVE_LIBHDFSPP_LIB_CROSS_PLATFORM_SYSCALL
  19. #define NATIVE_LIBHDFSPP_LIB_CROSS_PLATFORM_SYSCALL
  20. #include <string>
  21. /**
  22. * The {@link XPlatform} namespace contains components that
  23. * aid in writing cross-platform code.
  24. */
  25. namespace XPlatform {
  26. class Syscall {
  27. public:
  28. /**
  29. * Writes the given string to the application's
  30. * standard output stream.
  31. *
  32. * @param message The string to write to stdout.
  33. * @returns A boolean indicating whether the write
  34. * was successful.
  35. */
  36. static bool WriteToStdout(const std::string& message);
  37. /**
  38. * Writes the given char pointer to the application's
  39. * standard output stream.
  40. *
  41. * @param message The char pointer to write to stdout.
  42. * @returns A boolean indicating whether the write
  43. * was successful.
  44. */
  45. static int WriteToStdout(const char* message);
  46. /**
  47. * Checks whether the {@link str} argument matches the {@link pattern}
  48. * argument, which is a shell wildcard pattern.
  49. *
  50. * @param pattern The wildcard pattern to use.
  51. * @param str The string to match.
  52. * @returns A boolean indicating whether the given {@link str}
  53. * matches {@link pattern}.
  54. */
  55. static bool FnMatch(const std::string& pattern, const std::string& str);
  56. /**
  57. * Clears the given {@link buffer} upto {@link sz_bytes} by
  58. * filling them with zeros. This method is immune to compiler
  59. * optimizations and guarantees that the first {@link sz_bytes} of
  60. * {@link buffer} is cleared. The {@link buffer} must be at least
  61. * as big as {@link sz_bytes}, the behaviour is undefined otherwise.
  62. *
  63. * @param buffer the pointer to the buffer to clear.
  64. * @param sz_bytes the count of the bytes to clear.
  65. */
  66. static void ClearBufferSafely(void* buffer, size_t sz_bytes);
  67. /**
  68. * Performs a case insensitive equality comparison for the two
  69. * given strings {@link a} and {@link b}.
  70. *
  71. * @param a the first string parameter to compare.
  72. * @param b the second string parameter to compare.
  73. * @returns A boolean indicating whether to two strings are the
  74. * same irrespective of their case. Returns true if they match,
  75. * else false.
  76. */
  77. static bool StringCompareIgnoreCase(const std::string& a,
  78. const std::string& b);
  79. private:
  80. static bool WriteToStdoutImpl(const char* message);
  81. };
  82. } // namespace XPlatform
  83. #endif