Skip to content

Commit

Permalink
Use the more portable ptrdiff_t type instead of int.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlazar committed Feb 8, 2012
1 parent d540f17 commit 9f07c3e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 5 additions & 4 deletions base64encode.c
Expand Up @@ -8,6 +8,7 @@ This is part of the libb64 project, and has been placed in the public domain.
For details, see http://sourceforge.net/projects/libb64
*/

#include <stddef.h>
#include <stdint.h>
#include "base64encode.h"

Expand All @@ -22,7 +23,7 @@ char base64_encode_value(uint8_t value) {
return encoding[value];
}

int base64_encode_update(base64_encodestate *S, const uint8_t *data, uint64_t datalen, char *encoded) {
ptrdiff_t base64_encode_update(base64_encodestate *S, const uint8_t *data, uint64_t datalen, char *encoded) {
char *encoded_begin = encoded;
const uint8_t *currbyte = data;
const uint8_t *data_end = data + datalen;
Expand Down Expand Up @@ -71,7 +72,7 @@ int base64_encode_update(base64_encodestate *S, const uint8_t *data, uint64_t da
return encoded - encoded_begin;
}

int base64_encode_final(base64_encodestate *S, char *encoded) {
ptrdiff_t base64_encode_final(base64_encodestate *S, char *encoded) {
char *encoded_begin = encoded;

switch (S->step) {
Expand All @@ -91,8 +92,8 @@ int base64_encode_final(base64_encodestate *S, char *encoded) {
return encoded - encoded_begin;
}

int base64_encode(const uint8_t *data, uint64_t datalen, char *encoded) {
int c = 0;
ptrdiff_t base64_encode(const uint8_t *data, uint64_t datalen, char *encoded) {
ptrdiff_t c = 0;

base64_encodestate S;
base64_encode_init(&S);
Expand Down
7 changes: 4 additions & 3 deletions base64encode.h
Expand Up @@ -11,6 +11,7 @@ For details, see http://sourceforge.net/projects/libb64
#ifndef BASE64_ENCODE_H
#define BASE64_ENCODE_H

#include <stddef.h>
#include <stdint.h>

typedef enum {
Expand All @@ -24,8 +25,8 @@ typedef struct {

void base64_encode_init(base64_encodestate *);
char base64_encode_value(uint8_t);
int base64_encode_update(base64_encodestate *, const uint8_t *, uint64_t, char *);
int base64_encode_final(base64_encodestate *, char *);
int base64_encode(const uint8_t *, uint64_t, char *);
ptrdiff_t base64_encode_update(base64_encodestate *, const uint8_t *, uint64_t, char *);
ptrdiff_t base64_encode_final(base64_encodestate *, char *);
ptrdiff_t base64_encode(const uint8_t *, uint64_t, char *);

#endif /* BASE64_ENCODE_H */

0 comments on commit 9f07c3e

Please sign in to comment.