rugged 0.22.2 → 0.23.0b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/rugged.c +1 -2
  3. data/ext/rugged/rugged_branch_collection.c +6 -44
  4. data/ext/rugged/rugged_config.c +7 -3
  5. data/ext/rugged/rugged_diff_delta.c +1 -1
  6. data/ext/rugged/rugged_diff_line.c +1 -1
  7. data/ext/rugged/rugged_object.c +2 -2
  8. data/ext/rugged/rugged_reference_collection.c +12 -56
  9. data/ext/rugged/rugged_remote.c +4 -33
  10. data/ext/rugged/rugged_remote_collection.c +1 -1
  11. data/ext/rugged/rugged_repo.c +10 -36
  12. data/ext/rugged/rugged_settings.c +3 -3
  13. data/ext/rugged/rugged_tree.c +1 -1
  14. data/lib/rugged/version.rb +1 -1
  15. data/vendor/libgit2/CMakeLists.txt +10 -3
  16. data/vendor/libgit2/COPYING +15 -21
  17. data/vendor/libgit2/include/git2/annotated_commit.h +20 -3
  18. data/vendor/libgit2/include/git2/branch.h +20 -16
  19. data/vendor/libgit2/include/git2/checkout.h +32 -18
  20. data/vendor/libgit2/include/git2/cherrypick.h +2 -2
  21. data/vendor/libgit2/include/git2/clone.h +4 -10
  22. data/vendor/libgit2/include/git2/config.h +66 -12
  23. data/vendor/libgit2/include/git2/describe.h +3 -2
  24. data/vendor/libgit2/include/git2/diff.h +3 -3
  25. data/vendor/libgit2/include/git2/errors.h +1 -0
  26. data/vendor/libgit2/include/git2/filter.h +21 -5
  27. data/vendor/libgit2/include/git2/index.h +32 -0
  28. data/vendor/libgit2/include/git2/merge.h +20 -3
  29. data/vendor/libgit2/include/git2/oid.h +1 -1
  30. data/vendor/libgit2/include/git2/pack.h +13 -0
  31. data/vendor/libgit2/include/git2/patch.h +3 -6
  32. data/vendor/libgit2/include/git2/rebase.h +8 -12
  33. data/vendor/libgit2/include/git2/refs.h +19 -29
  34. data/vendor/libgit2/include/git2/remote.h +5 -11
  35. data/vendor/libgit2/include/git2/repository.h +44 -15
  36. data/vendor/libgit2/include/git2/reset.h +19 -10
  37. data/vendor/libgit2/include/git2/revert.h +2 -2
  38. data/vendor/libgit2/include/git2/submodule.h +3 -9
  39. data/vendor/libgit2/include/git2/sys/config.h +3 -1
  40. data/vendor/libgit2/include/git2/sys/filter.h +10 -2
  41. data/vendor/libgit2/include/git2/sys/hashsig.h +49 -22
  42. data/vendor/libgit2/include/git2/transport.h +1 -1
  43. data/vendor/libgit2/include/git2/types.h +10 -3
  44. data/vendor/libgit2/include/git2/version.h +3 -2
  45. data/vendor/libgit2/src/annotated_commit.c +28 -0
  46. data/vendor/libgit2/src/array.h +19 -8
  47. data/vendor/libgit2/src/attr.c +95 -35
  48. data/vendor/libgit2/src/attr_file.c +51 -17
  49. data/vendor/libgit2/src/attr_file.h +37 -10
  50. data/vendor/libgit2/src/attrcache.c +13 -7
  51. data/vendor/libgit2/src/attrcache.h +1 -0
  52. data/vendor/libgit2/src/blame.c +26 -2
  53. data/vendor/libgit2/src/blame_git.c +6 -2
  54. data/vendor/libgit2/src/blob.c +6 -8
  55. data/vendor/libgit2/src/branch.c +55 -43
  56. data/vendor/libgit2/src/buf_text.c +13 -6
  57. data/vendor/libgit2/src/buffer.c +110 -25
  58. data/vendor/libgit2/src/buffer.h +18 -0
  59. data/vendor/libgit2/src/checkout.c +164 -92
  60. data/vendor/libgit2/src/checkout.h +0 -7
  61. data/vendor/libgit2/src/cherrypick.c +13 -7
  62. data/vendor/libgit2/src/clone.c +23 -25
  63. data/vendor/libgit2/src/commit.c +3 -3
  64. data/vendor/libgit2/src/common.h +23 -1
  65. data/vendor/libgit2/src/config.c +137 -19
  66. data/vendor/libgit2/src/config.h +2 -2
  67. data/vendor/libgit2/src/config_cache.c +2 -1
  68. data/vendor/libgit2/src/config_file.c +39 -18
  69. data/vendor/libgit2/src/config_file.h +1 -1
  70. data/vendor/libgit2/src/crlf.c +1 -1
  71. data/vendor/libgit2/src/delta-apply.c +3 -2
  72. data/vendor/libgit2/src/delta.c +25 -6
  73. data/vendor/libgit2/src/describe.c +2 -0
  74. data/vendor/libgit2/src/diff.c +8 -5
  75. data/vendor/libgit2/src/diff_driver.c +39 -18
  76. data/vendor/libgit2/src/diff_file.c +1 -1
  77. data/vendor/libgit2/src/diff_patch.c +12 -6
  78. data/vendor/libgit2/src/diff_tform.c +21 -24
  79. data/vendor/libgit2/src/filebuf.c +14 -12
  80. data/vendor/libgit2/src/fileops.c +61 -18
  81. data/vendor/libgit2/src/fileops.h +11 -2
  82. data/vendor/libgit2/src/filter.c +351 -99
  83. data/vendor/libgit2/src/filter.h +17 -0
  84. data/vendor/libgit2/src/global.c +38 -9
  85. data/vendor/libgit2/src/hash/hash_generic.c +1 -1
  86. data/vendor/libgit2/src/hashsig.c +28 -16
  87. data/vendor/libgit2/src/ignore.c +2 -2
  88. data/vendor/libgit2/src/index.c +159 -42
  89. data/vendor/libgit2/src/index.h +29 -0
  90. data/vendor/libgit2/src/indexer.c +11 -2
  91. data/vendor/libgit2/src/integer.h +96 -0
  92. data/vendor/libgit2/src/iterator.c +5 -3
  93. data/vendor/libgit2/src/khash.h +41 -29
  94. data/vendor/libgit2/src/merge.c +48 -35
  95. data/vendor/libgit2/src/merge.h +0 -1
  96. data/vendor/libgit2/src/merge_file.c +13 -0
  97. data/vendor/libgit2/src/mwindow.c +1 -1
  98. data/vendor/libgit2/src/notes.c +1 -1
  99. data/vendor/libgit2/src/odb.c +13 -11
  100. data/vendor/libgit2/src/odb_loose.c +22 -10
  101. data/vendor/libgit2/src/odb_mempack.c +4 -2
  102. data/vendor/libgit2/src/offmap.h +3 -2
  103. data/vendor/libgit2/src/oid.c +1 -1
  104. data/vendor/libgit2/src/oidmap.h +2 -1
  105. data/vendor/libgit2/src/openssl_stream.c +6 -3
  106. data/vendor/libgit2/src/pack-objects.c +273 -12
  107. data/vendor/libgit2/src/pack-objects.h +10 -0
  108. data/vendor/libgit2/src/pack.c +17 -6
  109. data/vendor/libgit2/src/pack.h +1 -3
  110. data/vendor/libgit2/src/path.c +68 -38
  111. data/vendor/libgit2/src/pathspec.c +3 -0
  112. data/vendor/libgit2/src/pool.c +9 -8
  113. data/vendor/libgit2/src/posix.c +11 -1
  114. data/vendor/libgit2/src/push.c +15 -17
  115. data/vendor/libgit2/src/push.h +1 -6
  116. data/vendor/libgit2/src/rebase.c +77 -35
  117. data/vendor/libgit2/src/refdb_fs.c +2 -2
  118. data/vendor/libgit2/src/refs.c +107 -81
  119. data/vendor/libgit2/src/refs.h +2 -2
  120. data/vendor/libgit2/src/refspec.c +3 -0
  121. data/vendor/libgit2/src/remote.c +19 -21
  122. data/vendor/libgit2/src/repository.c +258 -67
  123. data/vendor/libgit2/src/repository.h +31 -16
  124. data/vendor/libgit2/src/reset.c +28 -12
  125. data/vendor/libgit2/src/revert.c +12 -7
  126. data/vendor/libgit2/src/revwalk.c +3 -5
  127. data/vendor/libgit2/src/revwalk.h +1 -1
  128. data/vendor/libgit2/src/sortedcache.c +5 -3
  129. data/vendor/libgit2/src/stash.c +3 -5
  130. data/vendor/libgit2/src/strmap.h +2 -1
  131. data/vendor/libgit2/src/submodule.c +5 -6
  132. data/vendor/libgit2/src/tag.c +7 -5
  133. data/vendor/libgit2/src/transaction.c +1 -1
  134. data/vendor/libgit2/src/transports/cred.c +5 -2
  135. data/vendor/libgit2/src/transports/git.c +2 -3
  136. data/vendor/libgit2/src/transports/local.c +15 -34
  137. data/vendor/libgit2/src/transports/smart.c +1 -1
  138. data/vendor/libgit2/src/transports/smart_pkt.c +58 -18
  139. data/vendor/libgit2/src/transports/smart_protocol.c +2 -2
  140. data/vendor/libgit2/src/transports/winhttp.c +2 -2
  141. data/vendor/libgit2/src/tree.c +7 -5
  142. data/vendor/libgit2/src/tsort.c +3 -1
  143. data/vendor/libgit2/src/util.c +25 -0
  144. data/vendor/libgit2/src/util.h +31 -27
  145. data/vendor/libgit2/src/vector.c +2 -7
  146. data/vendor/libgit2/src/win32/dir.c +5 -3
  147. data/vendor/libgit2/src/win32/git2.rc +8 -4
  148. data/vendor/libgit2/src/win32/mingw-compat.h +7 -0
  149. data/vendor/libgit2/src/win32/msvc-compat.h +3 -0
  150. data/vendor/libgit2/src/win32/posix.h +1 -3
  151. data/vendor/libgit2/src/win32/posix_w32.c +31 -7
  152. data/vendor/libgit2/src/win32/utf-conv.c +1 -3
  153. data/vendor/libgit2/src/zstream.c +1 -1
  154. metadata +5 -5
  155. data/vendor/libgit2/src/bswap.h +0 -97
@@ -29,14 +29,9 @@ GIT_INLINE(size_t) compute_new_size(git_vector *v)
29
29
 
30
30
  GIT_INLINE(int) resize_vector(git_vector *v, size_t new_size)
31
31
  {
32
- size_t new_bytes = new_size * sizeof(void *);
33
32
  void *new_contents;
34
33
 
35
- /* Check for overflow */
36
- if (new_bytes / sizeof(void *) != new_size)
37
- GITERR_CHECK_ALLOC(NULL);
38
-
39
- new_contents = git__realloc(v->contents, new_bytes);
34
+ new_contents = git__reallocarray(v->contents, new_size, sizeof(void *));
40
35
  GITERR_CHECK_ALLOC(new_contents);
41
36
 
42
37
  v->_alloc_size = new_size;
@@ -51,7 +46,7 @@ int git_vector_dup(git_vector *v, const git_vector *src, git_vector_cmp cmp)
51
46
 
52
47
  assert(v && src);
53
48
 
54
- bytes = src->length * sizeof(void *);
49
+ GITERR_CHECK_ALLOC_MULTIPLY(&bytes, src->length, sizeof(void *));
55
50
 
56
51
  v->_alloc_size = src->length;
57
52
  v->_cmp = cmp ? cmp : src->_cmp;
@@ -11,16 +11,18 @@ git__DIR *git__opendir(const char *dir)
11
11
  {
12
12
  git_win32_path filter_w;
13
13
  git__DIR *new = NULL;
14
- size_t dirlen;
14
+ size_t dirlen, alloclen;
15
15
 
16
16
  if (!dir || !git_win32__findfirstfile_filter(filter_w, dir))
17
17
  return NULL;
18
18
 
19
19
  dirlen = strlen(dir);
20
20
 
21
- new = git__calloc(sizeof(*new) + dirlen + 1, 1);
22
- if (!new)
21
+ if (GIT_ADD_SIZET_OVERFLOW(&alloclen, sizeof(*new), dirlen) ||
22
+ GIT_ADD_SIZET_OVERFLOW(&alloclen, alloclen, 1) ||
23
+ !(new = git__calloc(1, alloclen)))
23
24
  return NULL;
25
+
24
26
  memcpy(new->dir, dir, dirlen);
25
27
 
26
28
  new->h = FindFirstFileW(filter_w, &new->f);
@@ -2,12 +2,16 @@
2
2
  #include "../../include/git2/version.h"
3
3
 
4
4
  #ifndef LIBGIT2_FILENAME
5
- # define LIBGIT2_FILENAME "git2"
5
+ # define LIBGIT2_FILENAME "git2"
6
+ #endif
7
+
8
+ #ifndef LIBGIT2_COMMENTS
9
+ # define LIBGIT2_COMMENTS "For more information visit http://libgit2.github.com/"
6
10
  #endif
7
11
 
8
12
  VS_VERSION_INFO VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
9
- FILEVERSION LIBGIT2_VER_MAJOR,LIBGIT2_VER_MINOR,LIBGIT2_VER_REVISION,0
10
- PRODUCTVERSION LIBGIT2_VER_MAJOR,LIBGIT2_VER_MINOR,LIBGIT2_VER_REVISION,0
13
+ FILEVERSION LIBGIT2_VER_MAJOR,LIBGIT2_VER_MINOR,LIBGIT2_VER_REVISION,LIBGIT2_VER_PATCH
14
+ PRODUCTVERSION LIBGIT2_VER_MAJOR,LIBGIT2_VER_MINOR,LIBGIT2_VER_REVISION,LIBGIT2_VER_PATCH
11
15
  FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
12
16
  #ifdef _DEBUG
13
17
  FILEFLAGS VS_FF_DEBUG
@@ -30,7 +34,7 @@ BEGIN
30
34
  VALUE "OriginalFilename", LIBGIT2_FILENAME ".dll\0"
31
35
  VALUE "ProductName", "libgit2\0"
32
36
  VALUE "ProductVersion", LIBGIT2_VERSION "\0"
33
- VALUE "Comments", "For more information visit http://libgit2.github.com/\0"
37
+ VALUE "Comments", LIBGIT2_COMMENTS "\0"
34
38
  END
35
39
  END
36
40
  BLOCK "VarFileInfo"
@@ -17,6 +17,13 @@
17
17
  #define stat _stati64
18
18
  #endif
19
19
 
20
+ #if _WIN32_WINNT < 0x0600 && !defined(__MINGW64_VERSION_MAJOR)
21
+ #undef MemoryBarrier
22
+ void __mingworg_MemoryBarrier(void);
23
+ #define MemoryBarrier __mingworg_MemoryBarrier
24
+ #define VOLUME_NAME_DOS 0x0
25
+ #endif
26
+
20
27
  #endif
21
28
 
22
29
  #endif /* INCLUDE_mingw_compat__ */
@@ -15,6 +15,9 @@
15
15
  typedef unsigned short mode_t;
16
16
  typedef SSIZE_T ssize_t;
17
17
 
18
+ #define strcasecmp(s1, s2) _stricmp(s1, s2)
19
+ #define strncasecmp(s1, s2, c) _strnicmp(s1, s2, c)
20
+
18
21
  #endif
19
22
 
20
23
  #define GIT_STDLIB_CALL __cdecl
@@ -32,8 +32,6 @@ extern int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags);
32
32
  extern int p_send(GIT_SOCKET socket, const void *buffer, size_t length, int flags);
33
33
  extern int p_inet_pton(int af, const char* src, void* dst);
34
34
 
35
- #define strcasecmp(s1, s2) _stricmp(s1, s2)
36
- #define strncasecmp(s1, s2, c) _strnicmp(s1, s2, c)
37
35
  extern int p_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr);
38
36
  extern int p_snprintf(char *buffer, size_t count, const char *format, ...) GIT_FORMAT_PRINTF(3, 4);
39
37
  extern int p_mkstemp(char *tmp_path);
@@ -41,7 +39,7 @@ extern int p_chdir(const char* path);
41
39
  extern int p_chmod(const char* path, mode_t mode);
42
40
  extern int p_rmdir(const char* path);
43
41
  extern int p_access(const char* path, mode_t mode);
44
- extern int p_ftruncate(int fd, long size);
42
+ extern int p_ftruncate(int fd, git_off_t size);
45
43
 
46
44
  /* p_lstat is almost but not quite POSIX correct. Specifically, the use of
47
45
  * ENOTDIR is wrong, in that it does not mean precisely that a non-directory
@@ -33,15 +33,37 @@
33
33
  * inheritable on Windows, so specify the flag to get default behavior back. */
34
34
  #define STANDARD_OPEN_FLAGS (_O_BINARY | _O_NOINHERIT)
35
35
 
36
+ /* Allowable mode bits on Win32. Using mode bits that are not supported on
37
+ * Win32 (eg S_IRWXU) is generally ignored, but Wine warns loudly about it
38
+ * so we simply remove them.
39
+ */
40
+ #define WIN32_MODE_MASK (_S_IREAD | _S_IWRITE)
41
+
36
42
  /* GetFinalPathNameByHandleW signature */
37
43
  typedef DWORD(WINAPI *PFGetFinalPathNameByHandleW)(HANDLE, LPWSTR, DWORD, DWORD);
38
44
 
39
- int p_ftruncate(int fd, long size)
45
+ /**
46
+ * Truncate or extend file.
47
+ *
48
+ * We now take a "git_off_t" rather than "long" because
49
+ * files may be longer than 2Gb.
50
+ */
51
+ int p_ftruncate(int fd, git_off_t size)
40
52
  {
41
- #if defined(_MSC_VER) && _MSC_VER >= 1500
42
- return _chsize_s(fd, size);
53
+ if (size < 0) {
54
+ errno = EINVAL;
55
+ return -1;
56
+ }
57
+
58
+ #if !defined(__MINGW32__) || defined(MINGW_HAS_SECURE_API)
59
+ return ((_chsize_s(fd, size) == 0) ? 0 : -1);
43
60
  #else
44
- return _chsize(fd, size);
61
+ /* TODO MINGW32 Find a replacement for _chsize() that handles big files. */
62
+ if (size > INT32_MAX) {
63
+ errno = EFBIG;
64
+ return -1;
65
+ }
66
+ return _chsize(fd, (long)size);
45
67
  #endif
46
68
  }
47
69
 
@@ -343,7 +365,7 @@ int p_open(const char *path, int flags, ...)
343
365
  va_end(arg_list);
344
366
  }
345
367
 
346
- return _wopen(buf, flags | STANDARD_OPEN_FLAGS, mode);
368
+ return _wopen(buf, flags | STANDARD_OPEN_FLAGS, mode & WIN32_MODE_MASK);
347
369
  }
348
370
 
349
371
  int p_creat(const char *path, mode_t mode)
@@ -353,7 +375,9 @@ int p_creat(const char *path, mode_t mode)
353
375
  if (git_win32_path_from_utf8(buf, path) < 0)
354
376
  return -1;
355
377
 
356
- return _wopen(buf, _O_WRONLY | _O_CREAT | _O_TRUNC | STANDARD_OPEN_FLAGS, mode);
378
+ return _wopen(buf,
379
+ _O_WRONLY | _O_CREAT | _O_TRUNC | STANDARD_OPEN_FLAGS,
380
+ mode & WIN32_MODE_MASK);
357
381
  }
358
382
 
359
383
  int p_getcwd(char *buffer_out, size_t size)
@@ -607,7 +631,7 @@ int p_access(const char* path, mode_t mode)
607
631
  if (git_win32_path_from_utf8(buf, path) < 0)
608
632
  return -1;
609
633
 
610
- return _waccess(buf, mode);
634
+ return _waccess(buf, mode & WIN32_MODE_MASK);
611
635
  }
612
636
 
613
637
  static int ensure_writable(wchar_t *fpath)
@@ -99,9 +99,7 @@ int git__utf8_to_16_alloc(wchar_t **dest, const char *src)
99
99
  return -1;
100
100
  }
101
101
 
102
- *dest = git__malloc(utf16_size * sizeof(wchar_t));
103
-
104
- if (!*dest) {
102
+ if (!(*dest = git__mallocarray(utf16_size, sizeof(wchar_t)))) {
105
103
  errno = ENOMEM;
106
104
  return -1;
107
105
  }
@@ -134,7 +134,7 @@ int git_zstream_deflatebuf(git_buf *out, const void *in, size_t in_len)
134
134
  while (!git_zstream_done(&zs)) {
135
135
  size_t step = git_zstream_suggest_output_len(&zs), written;
136
136
 
137
- if ((error = git_buf_grow(out, out->size + step)) < 0)
137
+ if ((error = git_buf_grow_by(out, step)) < 0)
138
138
  goto done;
139
139
 
140
140
  written = out->asize - out->size;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rugged
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.2
4
+ version: 0.23.0b1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chacon
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-17 00:00:00.000000000 Z
12
+ date: 2015-03-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler
@@ -250,7 +250,6 @@ files:
250
250
  - vendor/libgit2/src/blob.h
251
251
  - vendor/libgit2/src/branch.c
252
252
  - vendor/libgit2/src/branch.h
253
- - vendor/libgit2/src/bswap.h
254
253
  - vendor/libgit2/src/buf_text.c
255
254
  - vendor/libgit2/src/buf_text.h
256
255
  - vendor/libgit2/src/buffer.c
@@ -324,6 +323,7 @@ files:
324
323
  - vendor/libgit2/src/index.c
325
324
  - vendor/libgit2/src/index.h
326
325
  - vendor/libgit2/src/indexer.c
326
+ - vendor/libgit2/src/integer.h
327
327
  - vendor/libgit2/src/iterator.c
328
328
  - vendor/libgit2/src/iterator.h
329
329
  - vendor/libgit2/src/khash.h
@@ -506,9 +506,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
506
506
  version: 1.9.3
507
507
  required_rubygems_version: !ruby/object:Gem::Requirement
508
508
  requirements:
509
- - - ">="
509
+ - - ">"
510
510
  - !ruby/object:Gem::Version
511
- version: '0'
511
+ version: 1.3.1
512
512
  requirements: []
513
513
  rubyforge_project:
514
514
  rubygems_version: 2.2.2
@@ -1,97 +0,0 @@
1
- /*
2
- * Copyright (C) the libgit2 contributors. All rights reserved.
3
- *
4
- * This file is part of libgit2, distributed under the GNU GPL v2 with
5
- * a Linking Exception. For full terms see the included COPYING file.
6
- */
7
-
8
- #include "common.h"
9
-
10
- /*
11
- * Default version that the compiler ought to optimize properly with
12
- * constant values.
13
- */
14
- GIT_INLINE(uint32_t) default_swab32(uint32_t val)
15
- {
16
- return (((val & 0xff000000) >> 24) |
17
- ((val & 0x00ff0000) >> 8) |
18
- ((val & 0x0000ff00) << 8) |
19
- ((val & 0x000000ff) << 24));
20
- }
21
-
22
- #undef bswap32
23
-
24
- GIT_INLINE(uint16_t) default_swab16(uint16_t val)
25
- {
26
- return (((val & 0xff00) >> 8) |
27
- ((val & 0x00ff) << 8));
28
- }
29
-
30
- #undef bswap16
31
-
32
- #if defined(__GNUC__) && defined(__i386__)
33
-
34
- #define bswap32(x) ({ \
35
- uint32_t __res; \
36
- if (__builtin_constant_p(x)) { \
37
- __res = default_swab32(x); \
38
- } else { \
39
- __asm__("bswap %0" : "=r" (__res) : "0" ((uint32_t)(x))); \
40
- } \
41
- __res; })
42
-
43
- #define bswap16(x) ({ \
44
- uint16_t __res; \
45
- if (__builtin_constant_p(x)) { \
46
- __res = default_swab16(x); \
47
- } else { \
48
- __asm__("xchgb %b0,%h0" : "=q" (__res) : "0" ((uint16_t)(x))); \
49
- } \
50
- __res; })
51
-
52
- #elif defined(__GNUC__) && defined(__x86_64__)
53
-
54
- #define bswap32(x) ({ \
55
- uint32_t __res; \
56
- if (__builtin_constant_p(x)) { \
57
- __res = default_swab32(x); \
58
- } else { \
59
- __asm__("bswapl %0" : "=r" (__res) : "0" ((uint32_t)(x))); \
60
- } \
61
- __res; })
62
-
63
- #define bswap16(x) ({ \
64
- uint16_t __res; \
65
- if (__builtin_constant_p(x)) { \
66
- __res = default_swab16(x); \
67
- } else { \
68
- __asm__("xchgb %b0,%h0" : "=Q" (__res) : "0" ((uint16_t)(x))); \
69
- } \
70
- __res; })
71
-
72
- #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
73
-
74
- #include <stdlib.h>
75
-
76
- #define bswap32(x) _byteswap_ulong(x)
77
- #define bswap16(x) _byteswap_ushort(x)
78
-
79
- #endif
80
-
81
- #ifdef bswap32
82
-
83
- #undef ntohl
84
- #undef htonl
85
- #define ntohl(x) bswap32(x)
86
- #define htonl(x) bswap32(x)
87
-
88
- #endif
89
-
90
- #ifdef bswap16
91
-
92
- #undef ntohs
93
- #undef htons
94
- #define ntohs(x) bswap16(x)
95
- #define htons(x) bswap16(x)
96
-
97
- #endif