Skip to content

Commit 77f27d5

Browse files
committed
Fix some portability problems (get it to compile, at least, on HP's cc)
1 parent aa6970e commit 77f27d5

File tree

5 files changed

+34
-41
lines changed

5 files changed

+34
-41
lines changed

contrib/pgcrypto/crypt-blowfish.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,15 @@
3030
* hadn't seen his code).
3131
*/
3232

33-
#include <postgres.h>
33+
#include "postgres.h"
34+
3435
#include "px-crypt.h"
3536
#define __set_errno(v)
3637

3738
#ifndef __set_errno
3839
#define __set_errno(val) errno = (val)
3940
#endif
4041

41-
#undef __CONST
42-
#ifdef __GNUC__
43-
#define __CONST __const
44-
#else
45-
#define __CONST
46-
#endif
47-
4842
#ifdef __i386__
4943
#define BF_ASM 0 /* 1 */
5044
#define BF_SCALE 1
@@ -373,7 +367,7 @@ static unsigned char BF_atoi64[0x60] = {
373367
(dst) = tmp; \
374368
}
375369

376-
static int BF_decode(BF_word *dst, __CONST char *src, int size)
370+
static int BF_decode(BF_word *dst, const char *src, int size)
377371
{
378372
unsigned char *dptr = (unsigned char *)dst;
379373
unsigned char *end = dptr + size;
@@ -397,7 +391,7 @@ static int BF_decode(BF_word *dst, __CONST char *src, int size)
397391
return 0;
398392
}
399393

400-
static void BF_encode(char *dst, __CONST BF_word *src, int size)
394+
static void BF_encode(char *dst, const BF_word *src, int size)
401395
{
402396
unsigned char *sptr = (unsigned char *)src;
403397
unsigned char *end = sptr + size;
@@ -536,9 +530,9 @@ extern void _BF_body_r(BF_ctx *ctx);
536530

537531
#endif
538532

539-
static void BF_set_key(__CONST char *key, BF_key expanded, BF_key initial)
533+
static void BF_set_key(const char *key, BF_key expanded, BF_key initial)
540534
{
541-
__CONST char *ptr = key;
535+
const char *ptr = key;
542536
int i, j;
543537
BF_word tmp;
544538

@@ -556,7 +550,7 @@ static void BF_set_key(__CONST char *key, BF_key expanded, BF_key initial)
556550
}
557551
}
558552

559-
char *_crypt_blowfish_rn(__CONST char *key, __CONST char *setting,
553+
char *_crypt_blowfish_rn(const char *key, const char *setting,
560554
char *output, int size)
561555
{
562556
struct {

contrib/pgcrypto/crypt-des.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,13 @@
5858
* alignment).
5959
*/
6060

61-
#include <postgres.h>
61+
#include "postgres.h"
62+
6263
#include "px-crypt.h"
6364

6465
/* for ntohl/htonl */
6566
#include <netinet/in.h>
6667

67-
68-
/* We can't always assume gcc */
69-
#ifdef __GNUC__
70-
#define INLINE inline
71-
#endif
72-
7368
#define _PASSWORD_EFMT1 '_'
7469

7570
static uint8 IP[64] = {
@@ -200,7 +195,7 @@ static uint32 comp_maskl[8][128],
200195
static uint32 old_rawkey0,
201196
old_rawkey1;
202197

203-
static INLINE int
198+
static inline int
204199
ascii_to_bin(char ch)
205200
{
206201
if (ch > 'z')
@@ -611,6 +606,7 @@ do_des(uint32 l_in, uint32 r_in, uint32 * l_out, uint32 * r_out, int count)
611606
static int
612607
des_cipher(const char *in, char *out, long salt, int count)
613608
{
609+
uint32 buffer[2];
614610
uint32 l_out,
615611
r_out,
616612
rawl,
@@ -622,13 +618,20 @@ des_cipher(const char *in, char *out, long salt, int count)
622618

623619
setup_salt(salt);
624620

625-
rawl = ntohl(*((uint32 *) in)++);
626-
rawr = ntohl(*((uint32 *) in));
621+
/* copy data to avoid assuming input is word-aligned */
622+
memcpy(buffer, in, sizeof(buffer));
623+
624+
rawl = ntohl(buffer[0]);
625+
rawr = ntohl(buffer[1]);
627626

628627
retval = do_des(rawl, rawr, &l_out, &r_out, count);
629628

630-
*((uint32 *) out)++ = htonl(l_out);
631-
*((uint32 *) out) = htonl(r_out);
629+
buffer[0] = htonl(l_out);
630+
buffer[1] = htonl(r_out);
631+
632+
/* copy data to avoid assuming output is word-aligned */
633+
memcpy(out, buffer, sizeof(buffer));
634+
632635
return (retval);
633636
}
634637

contrib/pgcrypto/crypt-gensalt.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,13 @@
1010
* may not be compiled always. -- marko
1111
*/
1212

13-
#include <postgres.h>
13+
#include "postgres.h"
14+
1415
#include "px-crypt.h"
1516

1617
#include <errno.h>
1718
#ifndef __set_errno
18-
#define __set_errno(val) errno = (val)
19-
#endif
20-
21-
#undef __CONST
22-
#ifdef __GNUC__
23-
#define __CONST __const
24-
#else
25-
#define __CONST
19+
#define __set_errno(val) (errno = (val))
2620
#endif
2721

2822
typedef unsigned int BF_word;
@@ -31,7 +25,7 @@ unsigned char _crypt_itoa64[64 + 1] =
3125
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
3226

3327
char *_crypt_gensalt_traditional_rn(unsigned long count,
34-
__CONST char *input, int size, char *output, int output_size)
28+
const char *input, int size, char *output, int output_size)
3529
{
3630
if (size < 2 || output_size < 2 + 1 || (count && count != 25)) {
3731
if (output_size > 0) output[0] = '\0';
@@ -47,7 +41,7 @@ char *_crypt_gensalt_traditional_rn(unsigned long count,
4741
}
4842

4943
char *_crypt_gensalt_extended_rn(unsigned long count,
50-
__CONST char *input, int size, char *output, int output_size)
44+
const char *input, int size, char *output, int output_size)
5145
{
5246
unsigned long value;
5347

@@ -80,7 +74,7 @@ char *_crypt_gensalt_extended_rn(unsigned long count,
8074
}
8175

8276
char *_crypt_gensalt_md5_rn(unsigned long count,
83-
__CONST char *input, int size, char *output, int output_size)
77+
const char *input, int size, char *output, int output_size)
8478
{
8579
unsigned long value;
8680

@@ -121,7 +115,7 @@ char *_crypt_gensalt_md5_rn(unsigned long count,
121115
static unsigned char BF_itoa64[64 + 1] =
122116
"./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
123117

124-
static void BF_encode(char *dst, __CONST BF_word *src, int size)
118+
static void BF_encode(char *dst, const BF_word *src, int size)
125119
{
126120
unsigned char *sptr = (unsigned char *)src;
127121
unsigned char *end = sptr + size;
@@ -154,7 +148,7 @@ static void BF_encode(char *dst, __CONST BF_word *src, int size)
154148
}
155149

156150
char *_crypt_gensalt_blowfish_rn(unsigned long count,
157-
__CONST char *input, int size, char *output, int output_size)
151+
const char *input, int size, char *output, int output_size)
158152
{
159153
if (size < 16 || output_size < 7 + 22 + 1 ||
160154
(count && (count < 4 || count > 31))) {

contrib/pgcrypto/internal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $Id: internal.c,v 1.4 2001/08/21 00:42:41 momjian Exp $
29+
* $Id: internal.c,v 1.5 2001/10/15 19:12:48 tgl Exp $
3030
*/
3131

3232

@@ -134,7 +134,7 @@ int_sha1_update(PX_MD * h, const uint8 * data, uint dlen)
134134
{
135135
SHA1_CTX *ctx = (SHA1_CTX *) h->p.ptr;
136136

137-
SHA1Update(ctx, (const char *)data, dlen);
137+
SHA1Update(ctx, data, dlen);
138138
}
139139

140140
static void

contrib/rserv/rserv.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ _rserv_log_()
8787
if (TRIGGER_FIRED_BY_UPDATE(CurrentTriggerData->tg_event))
8888
newtuple = CurrentTriggerData->tg_newtuple;
8989

90+
#ifndef PG_FUNCTION_INFO_V1
9091
/*
9192
* Setting CurrentTriggerData to NULL prevents direct calls to trigger
9293
* functions in queries. Normally, trigger functions have to be called
9394
* by trigger manager code only.
9495
*/
9596
CurrentTriggerData = NULL;
97+
#endif
9698

9799
/* Connect to SPI manager */
98100
if ((ret = SPI_connect()) < 0)

0 commit comments

Comments
 (0)