Fix some portability problems (get it to compile, at least, on HP's cc)
authorTom Lane
Mon, 15 Oct 2001 19:15:18 +0000 (19:15 +0000)
committerTom Lane
Mon, 15 Oct 2001 19:15:18 +0000 (19:15 +0000)
contrib/pgcrypto/crypt-blowfish.c
contrib/pgcrypto/crypt-des.c
contrib/pgcrypto/crypt-gensalt.c
contrib/pgcrypto/internal.c
contrib/rserv/rserv.c

index 82056a806b61508a689f1f5262043426bf12fc19..1a9dba7dff58e736639bb15ff830ae013860f80c 100644 (file)
@@ -30,7 +30,8 @@
  * hadn't seen his code).
  */
 
-#include 
+#include "postgres.h"
+
 #include "px-crypt.h"
 #define __set_errno(v)
 
 #define __set_errno(val) errno = (val)
 #endif
 
-#undef __CONST
-#ifdef __GNUC__
-#define __CONST __const
-#else
-#define __CONST
-#endif
-
 #ifdef __i386__
 #define BF_ASM             0   /* 1 */
 #define BF_SCALE           1
@@ -373,7 +367,7 @@ static unsigned char BF_atoi64[0x60] = {
    (dst) = tmp; \
 }
 
-static int BF_decode(BF_word *dst, __CONST char *src, int size)
+static int BF_decode(BF_word *dst, const char *src, int size)
 {
    unsigned char *dptr = (unsigned char *)dst;
    unsigned char *end = dptr + size;
@@ -397,7 +391,7 @@ static int BF_decode(BF_word *dst, __CONST char *src, int size)
    return 0;
 }
 
-static void BF_encode(char *dst, __CONST BF_word *src, int size)
+static void BF_encode(char *dst, const BF_word *src, int size)
 {
    unsigned char *sptr = (unsigned char *)src;
    unsigned char *end = sptr + size;
@@ -536,9 +530,9 @@ extern void _BF_body_r(BF_ctx *ctx);
 
 #endif
 
-static void BF_set_key(__CONST char *key, BF_key expanded, BF_key initial)
+static void BF_set_key(const char *key, BF_key expanded, BF_key initial)
 {
-   __CONST char *ptr = key;
+   const char *ptr = key;
    int i, j;
    BF_word tmp;
 
@@ -556,7 +550,7 @@ static void BF_set_key(__CONST char *key, BF_key expanded, BF_key initial)
    }
 }
 
-char *_crypt_blowfish_rn(__CONST char *key, __CONST char *setting,
+char *_crypt_blowfish_rn(const char *key, const char *setting,
    char *output, int size)
 {
    struct {
index d9e12127b7743e49963a486cc300a4c209f011ab..de6b1865e37a0f49c7cff370090c2fd5b9c99faf 100644 (file)
  * alignment).
  */
 
-#include 
+#include "postgres.h"
+
 #include "px-crypt.h"
 
 /* for ntohl/htonl */
 #include 
 
-
-/* We can't always assume gcc */
-#ifdef __GNUC__
-#define INLINE inline
-#endif
-
 #define _PASSWORD_EFMT1 '_'
 
 static uint8 IP[64] = {
@@ -200,7 +195,7 @@ static uint32 comp_maskl[8][128],
 static uint32 old_rawkey0,
            old_rawkey1;
 
-static INLINE int
+static inline int
 ascii_to_bin(char ch)
 {
    if (ch > 'z')
@@ -611,6 +606,7 @@ do_des(uint32 l_in, uint32 r_in, uint32 * l_out, uint32 * r_out, int count)
 static int
 des_cipher(const char *in, char *out, long salt, int count)
 {
+   uint32      buffer[2];
    uint32      l_out,
                r_out,
                rawl,
@@ -622,13 +618,20 @@ des_cipher(const char *in, char *out, long salt, int count)
 
    setup_salt(salt);
 
-   rawl = ntohl(*((uint32 *) in)++);
-   rawr = ntohl(*((uint32 *) in));
+   /* copy data to avoid assuming input is word-aligned */
+   memcpy(buffer, in, sizeof(buffer));
+
+   rawl = ntohl(buffer[0]);
+   rawr = ntohl(buffer[1]);
 
    retval = do_des(rawl, rawr, &l_out, &r_out, count);
 
-   *((uint32 *) out)++ = htonl(l_out);
-   *((uint32 *) out) = htonl(r_out);
+   buffer[0] = htonl(l_out);
+   buffer[1] = htonl(r_out);
+
+   /* copy data to avoid assuming output is word-aligned */
+   memcpy(out, buffer, sizeof(buffer));
+
    return (retval);
 }
 
index 8bb17147334fd3462f027b74896e6435641dba51..6913826842467ed987e838bc8a86c03d8e4c36cf 100644 (file)
  * may not be compiled always.        -- marko
  */
 
-#include 
+#include "postgres.h"
+
 #include "px-crypt.h"
 
 #include 
 #ifndef __set_errno
-#define __set_errno(val) errno = (val)
-#endif
-
-#undef __CONST
-#ifdef __GNUC__
-#define __CONST __const
-#else
-#define __CONST
+#define __set_errno(val) (errno = (val))
 #endif
 
 typedef unsigned int BF_word;
@@ -31,7 +25,7 @@ unsigned char _crypt_itoa64[64 + 1] =
    "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 
 char *_crypt_gensalt_traditional_rn(unsigned long count,
-   __CONST char *input, int size, char *output, int output_size)
+   const char *input, int size, char *output, int output_size)
 {
    if (size < 2 || output_size < 2 + 1 || (count && count != 25)) {
        if (output_size > 0) output[0] = '\0';
@@ -47,7 +41,7 @@ char *_crypt_gensalt_traditional_rn(unsigned long count,
 }
 
 char *_crypt_gensalt_extended_rn(unsigned long count,
-   __CONST char *input, int size, char *output, int output_size)
+   const char *input, int size, char *output, int output_size)
 {
    unsigned long value;
 
@@ -80,7 +74,7 @@ char *_crypt_gensalt_extended_rn(unsigned long count,
 }
 
 char *_crypt_gensalt_md5_rn(unsigned long count,
-   __CONST char *input, int size, char *output, int output_size)
+   const char *input, int size, char *output, int output_size)
 {
    unsigned long value;
 
@@ -121,7 +115,7 @@ char *_crypt_gensalt_md5_rn(unsigned long count,
 static unsigned char BF_itoa64[64 + 1] =
    "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
 
-static void BF_encode(char *dst, __CONST BF_word *src, int size)
+static void BF_encode(char *dst, const BF_word *src, int size)
 {
    unsigned char *sptr = (unsigned char *)src;
    unsigned char *end = sptr + size;
@@ -154,7 +148,7 @@ static void BF_encode(char *dst, __CONST BF_word *src, int size)
 }
 
 char *_crypt_gensalt_blowfish_rn(unsigned long count,
-   __CONST char *input, int size, char *output, int output_size)
+   const char *input, int size, char *output, int output_size)
 {
    if (size < 16 || output_size < 7 + 22 + 1 ||
        (count && (count < 4 || count > 31))) {
index 1debd2b3884fa3d08db18ed74834a674a26551cf..421f5f1739286435d03f77278a8a8f4030a17ad4 100644 (file)
@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: internal.c,v 1.4 2001/08/21 00:42:41 momjian Exp $
+ * $Id: internal.c,v 1.5 2001/10/15 19:12:48 tgl Exp $
  */
 
 
@@ -134,7 +134,7 @@ int_sha1_update(PX_MD * h, const uint8 * data, uint dlen)
 {
    SHA1_CTX   *ctx = (SHA1_CTX *) h->p.ptr;
 
-   SHA1Update(ctx, (const char *)data, dlen);
+   SHA1Update(ctx, data, dlen);
 }
 
 static void
index 4a7d3aed350d5d8a872d9368479b4bab1e00cb6b..02c71220d62567a9ca02084d5299b1ad4bcade17 100644 (file)
@@ -87,12 +87,14 @@ _rserv_log_()
    if (TRIGGER_FIRED_BY_UPDATE(CurrentTriggerData->tg_event))
        newtuple = CurrentTriggerData->tg_newtuple;
 
+#ifndef PG_FUNCTION_INFO_V1
    /*
     * Setting CurrentTriggerData to NULL prevents direct calls to trigger
     * functions in queries. Normally, trigger functions have to be called
     * by trigger manager code only.
     */
    CurrentTriggerData = NULL;
+#endif
 
    /* Connect to SPI manager */
    if ((ret = SPI_connect()) < 0)