+AC_CHECK_SIZEOF(ssize_t)
+
+dnl Try to figure out whether gssize should be long or int
+AC_MSG_CHECKING([for the appropriate definition for ssize_t])
+
+case $ac_cv_sizeof_ssize_t in
+ $ac_cv_sizeof_short)
+ glib_ssize_type=short
+ ;;
+ $ac_cv_sizeof_int)
+ glib_ssize_type=int
+ ;;
+ $ac_cv_sizeof_long)
+ glib_ssize_type=long
+ ;;
+ $ac_cv_sizeof_long_long)
+ glib_ssize_type='long long'
+ ;;
+ $ac_cv_sizeof__int64)
+ glib_ssize_type='__int64'
+ ;;
+ *) AC_MSG_ERROR([No type matching ssize_t in size])
+ ;;
+esac
+
+dnl If int/long are the same size, we see which one produces
+dnl warnings when used in the location as ssize_t. (This matters
+dnl on Android where ssize_t is long and size_t is unsigned int)
+dnl
+AS_IF([test $ac_cv_sizeof_ssize_t = $ac_cv_sizeof_int &&
+ test $ac_cv_sizeof_ssize_t = $ac_cv_sizeof_long], [
+ GLIB_CHECK_COMPILE_WARNINGS([AC_LANG_SOURCE([[
+#if defined(_AIX) && !defined(__GNUC__)
+#pragma options langlvl=stdc89
+#endif
+#include <stddef.h>
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+int main ()
+{
+ ssize_t s = 1;
+ int *size_int = &s;
+ return (int)*size_int;
+}
+ ]])],glib_ssize_type=int,
+ [GLIB_CHECK_COMPILE_WARNINGS([AC_LANG_SOURCE([[
+#if defined(_AIX) && !defined(__GNUC__)
+#pragma options langlvl=stdc89
+#endif
+#include <stddef.h>
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+int main ()
+{
+ ssize_t s = 1;
+ long *size_long = &s;
+ return (int)*size_long;
+}
+ ]])],glib_ssize_type=long)])
+])
+
+AC_MSG_RESULT($glib_ssize_type)
+