version.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * version.h - version handling routines
  4. *
  5. * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright © 2011-2014 Guillem Jover <guillem@debian.org>
  7. *
  8. * This is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. #ifndef LIBDPKG_VERSION_H
  22. #define LIBDPKG_VERSION_H
  23. #include <stdbool.h>
  24. #include <dpkg/macros.h>
  25. DPKG_BEGIN_DECLS
  26. /**
  27. * @defgroup version Version handling
  28. * @ingroup dpkg-public
  29. * @{
  30. */
  31. /**
  32. * Data structure representing a Debian version.
  33. *
  34. * @see deb-version(5)
  35. */
  36. struct dpkg_version {
  37. /** The epoch. It will be zero if no epoch is present. */
  38. unsigned int epoch;
  39. /** The upstream part of the version. */
  40. const char *version;
  41. /** The Debian revision part of the version. */
  42. const char *revision;
  43. };
  44. /**
  45. * Compound literal for a dpkg_version.
  46. */
  47. #define DPKG_VERSION_OBJECT(e, v, r) \
  48. (struct dpkg_version){ .epoch = (e), .version = (v), .revision = (r) }
  49. /**
  50. * Enum constants for the supported relation operations that can be done
  51. * on Debian versions.
  52. */
  53. enum dpkg_relation {
  54. /** The “none” relation, sentinel value. */
  55. DPKG_RELATION_NONE = 0,
  56. /** Equality relation (‘=’). */
  57. DPKG_RELATION_EQ = DPKG_BIT(0),
  58. /** Less than relation (‘<<’). */
  59. DPKG_RELATION_LT = DPKG_BIT(1),
  60. /** Less than or equal to relation (‘<=’). */
  61. DPKG_RELATION_LE = DPKG_RELATION_LT | DPKG_RELATION_EQ,
  62. /** Greater than relation (‘>>’). */
  63. DPKG_RELATION_GT = DPKG_BIT(2),
  64. /** Greater than or equal to relation (‘>=’). */
  65. DPKG_RELATION_GE = DPKG_RELATION_GT | DPKG_RELATION_EQ,
  66. };
  67. void dpkg_version_blank(struct dpkg_version *version);
  68. bool dpkg_version_is_informative(const struct dpkg_version *version);
  69. int dpkg_version_compare(const struct dpkg_version *a,
  70. const struct dpkg_version *b);
  71. bool dpkg_version_relate(const struct dpkg_version *a,
  72. enum dpkg_relation rel,
  73. const struct dpkg_version *b);
  74. /** @} */
  75. DPKG_END_DECLS
  76. #endif /* LIBDPKG_VERSION_H */