static int ft_pop_line(char *buffer, char **line) { char *out_str; size_t out_offset; size_t buff_len; int retval; retval = (ft_memchr(buffer, '\n', BUFF_SIZE + 1)) ? 1 : 0; if (ft_memchr(buffer, '\n', BUFF_SIZE)) buff_len = (char *)ft_memchr(buffer, '\n', BUFF_SIZE + 1) - buffer + 1; else buff_len = (char *)ft_memchr(buffer, '\0', BUFF_SIZE + 1) - buffer + 1; out_offset = (*line) ? ft_strlen(*line) : 0; if ((out_str = ft_memalloc(out_offset + buff_len))) { if (*line) { ft_strcpy(out_str, *line); free(*line); } ft_memcpy(out_str + out_offset, buffer, buff_len - 1); *line = out_str; ft_rotate_buff(buffer, BUFF_SIZE + 1, buff_len); return (retval); } return (-1); }
static int get_line(char *buf, char **line) { char c_eol; int end; size_t len_buf; size_t len_count; char *tmp; tmp = NULL; end = ft_memchr(buf, '\n', BUFF_SIZE) ? 1 : 0; c_eol = end ? '\n' : '\0'; len_buf = (char *)ft_memchr(buf, c_eol, BUFF_SIZE + 1) - buf + 1; len_count = *line ? ft_strlen(*line) : 0; if (!(tmp = ft_strnew(len_count + len_buf))) return (-1); if (*line) { ft_strcpy(tmp, *line); free(*line); } ft_memcpy(tmp + len_count, buf, len_buf - 1); *line = tmp; rotate(buf, BUFF_SIZE, len_buf); return (end); }
char *ft_strchr(const char *s, int c) { char *x; x = ft_memchr(s, c, ft_strlen(s) + 1); return (x); }
int get_next_line(int const fd_const, char **line) { static t_gnl gnl[64] = {{{0}, 0, 0, 0}}; t_norme n; if (!(n.n = NULL) && (!line || fd_const < 0)) return (-1); n.f = fd_const % 64; *line = NULL; while (!n.n) { if (gnl[n.f].i == gnl[n.f].r && !(gnl[n.f].i = 0)) { if ((gnl[n.f].r = read(fd_const, gnl[n.f].buf, BUFF_SIZE)) <= 0) { n.t = gnl[n.f].r; gnl[n.f].r = 0; return (*line ? 1 : n.t); } } n.n = ft_memchr(&gnl[n.f].buf[gnl[n.f].i], 10, gnl[n.f].r - gnl[n.f].i); n.l = (n.n) ? n.n - &gnl[n.f].buf[gnl[n.f].i] : gnl[n.f].r - gnl[n.f].i; *line = (*line) ? ft_strnjoin(*line, &gnl[n.f].buf[gnl[n.f].i], n.l, &gnl[n.f].s) : ft_strndup(&gnl[n.f].buf[gnl[n.f].i], n.l, &gnl[n.f].s); gnl[n.f].i = (n.n) ? gnl[n.f].i + n.l + 1 : gnl[n.f].r; } return (1); }
void *ft_memchr(const void *s, int c, size_t n) { if (n == 0) return (NULL); if (*(char *)s == (unsigned char)c) return ((char *)s); return (ft_memchr(s + 1, c, n - 1)); }
void *ft_memchr(const void *s, int c, size_t n) { if (!n) return (NULL); if (*(unsigned char *)s == (unsigned char)c) return ((void *)s); else return (ft_memchr(s + 1, c, n - 1)); }
void *ft_memccpy(void *dst, const void *src, int c, size_t n) { void *str; str = ft_memchr(src, c, n); if (str != NULL) return (ft_memcpy(dst, src, str - src + 1)); ft_memcpy(dst, src, n); return (NULL); }
void *ft_memchr(const void *s, int c, size_t n) { if (n) { if (*((unsigned char *)s) == (unsigned char)c) return ((void *)s); else return (ft_memchr(++s, c, --n)); } return (NULL); }
static ssize_t ft_len_to_endline(int fd, t_buf *buf) { char *endline; if (buf->cursor >= (size_t)buf->size) { buf->size = read(fd, buf->buf, BUFF_SIZE); buf->cursor = 0; } if (buf->size <= 0) return (-1); endline = ft_memchr(buf->buf + buf->cursor, '\n', buf->size - buf->cursor); if (endline == NULL) return (-1); else return (endline - (buf->buf + buf->cursor)); }
int main(void) { char *s; char *s1; char *s2; s = "qwertyuiop"; s1 = ft_memchr(s, 121, 11); s2 = memchr(s, 121, 11); write(1, s, 11); write(1, "\n", 1); write(1, s1, 6); write(1, "\n", 1); write(1, s2, 6); write(1, "\n", 1); return (0); }
size_t ft_strlcat(char *dst, const char *src, size_t size) { char *str; size_t len; if (!(str = ft_memchr(dst, 0, size))) return (size + ft_strlen(src)); len = (size_t)(str - dst) + ft_strlen(src); while (*src && (size_t)(str - dst) + 1 < size) { *str = *src; str++; src++; } *str = 0; return (len); }
size_t ft_strlcat(char *dst, const char *src, size_t size) { char *str; size_t toret; if (!(str = ft_memchr(dst, '\0', size))) return (size + ft_strlen(src)); toret = (size_t)(str - dst) + ft_strlen(src); while ((size_t)(str - dst) < size - 1 && *src) { *str = *src; str++; src++; } *str = '\0'; return (toret); }
size_t ft_strlcat(char *dst, const char *src, size_t size) { char *d; char *s; size_t len; size_t dst_len; d = (char *)ft_memchr(dst, '\0', size); s = (char *)src; dst_len = ft_strlen(dst); len = dst_len + ft_strlen(s); if (!d) return (size + ft_strlen(src)); while (dst_len++ < size - 1 && *s) *d++ = *s++; *d = '\0'; return (len); }
void *ft_memccpy(void *dst, const void *src, int c, size_t n) { void *index; char *d; char *s; d = (char *)dst; s = (char *)src; index = ft_memchr(src, (unsigned char)c, n); if (index == NULL) { ft_memcpy(dst, src, n); return (NULL); } while (src++ <= index) *(d++) = *(s++); return (d); }
int main(int argc, char **argv) { int i; char *str; if (argc == 5) { i = atoi(argv[1]); if (i == 0) { str = (char *)ft_memchr(argv[2], atoi(argv[3]), atoi(argv[4])); if (str) printf("%s", str); else printf("(null)"); } } return (0); }
size_t ft_strlcat(char *dst, const char *src, size_t size) { char *cur; char *reader; size_t len; cur = (char *)ft_memchr(dst, '\0', size); if (cur == NULL) return (size + ft_strlen(src)); reader = (char *)src; len = (size_t)(cur - dst) + ft_strlen(reader); while ((size_t)(cur - dst) < size - 1 && *reader != '\0') { *cur = *reader; cur++; reader++; } *cur = '\0'; return (len); }
int create_line(char **buf, char **line) { char *tmp; int i; i = 0; tmp = ft_strcsub(*buf, '\n'); if (*line) *line = ft_strjoin(*line, tmp); else *line = ft_strdup(tmp); ft_memdel((void **)(&tmp)); if (ft_memchr(*buf, '\n', ft_strlen(*buf))) { while ((*buf)[i] != '\n') i++; *buf = ft_strsub(*buf, (i + 1), ft_strlen(*buf) - i); return (1); } return (0); }
int ft_read_buf(char **line, t_info *cur, int *len) { char *n; if ((n = ft_memchr(cur->start, (int)'\n', cur->offset)) == NULL) { if (ft_realloc(line, cur->start, cur->offset, len)) return (-1); cur->offset = 0; cur->start = NULL; } else { if (ft_realloc(line, cur->start, n - cur->start, len)) return (-1); cur->offset = cur->offset - (n + 1 - cur->start); cur->start = n + 1; return (1); } return (0); }
int get_next_line(int const fd, char **line) { ssize_t r; char *n; char *s; static t_buffer buf; t_list *chunk; r = 42; while (!buf.chunks || (!(n = ft_memchr(buf.CHUNK, '\n', buf.CHUNK_SIZE)) && r)) { if (!(s = ft_strnew(BUF_SIZE - 1)) || (r = read(fd, s, BUF_SIZE)) < 0 || !(chunk = ft_lstnew(s, r))) return (reset_buf(&buf, &s)); ft_lstadd(&buf.chunks, chunk); buf.size += r; } if (buf.size) return (set_next_line(&buf, n, line)); reset_buf(&buf, NULL); return (0); }
char *ft_strchr(const char *s, int c) { return (ft_memchr(s, c, ft_strlen(s) + 1)); }
char *ft_strchr(const char *s, int c) { return ((char *)ft_memchr((void *)s, c, ft_strlen(s) + 1)); }
tt_face_find_bdf_prop( TT_Face face, const char* property_name, BDF_PropertyRec *aprop ) { TT_BDF bdf = &face->bdf; FT_Size size = FT_FACE(face)->size; FT_Error error = FT_Err_Ok; FT_Byte* p; FT_UInt count; FT_Byte* strike; FT_Offset property_len; aprop->type = BDF_PROPERTY_TYPE_NONE; if ( bdf->loaded == 0 ) { error = tt_face_load_bdf_props( face, FT_FACE( face )->stream ); if ( error ) goto Exit; } count = bdf->num_strikes; p = bdf->table + 8; strike = p + 4 * count; error = FT_ERR( Invalid_Argument ); if ( size == NULL || property_name == NULL ) goto Exit; property_len = ft_strlen( property_name ); if ( property_len == 0 ) goto Exit; for ( ; count > 0; count-- ) { FT_UInt _ppem = FT_NEXT_USHORT( p ); FT_UInt _count = FT_NEXT_USHORT( p ); if ( _ppem == size->metrics.y_ppem ) { count = _count; goto FoundStrike; } strike += 10 * _count; } goto Exit; FoundStrike: p = strike; for ( ; count > 0; count-- ) { FT_UInt type = FT_PEEK_USHORT( p + 4 ); if ( ( type & 0x10 ) != 0 ) { FT_UInt32 name_offset = FT_PEEK_ULONG( p ); FT_UInt32 value = FT_PEEK_ULONG( p + 6 ); /* be a bit paranoid for invalid entries here */ if ( name_offset < bdf->strings_size && property_len < bdf->strings_size - name_offset && ft_strncmp( property_name, (const char*)bdf->strings + name_offset, bdf->strings_size - name_offset ) == 0 ) { switch ( type & 0x0F ) { case 0x00: /* string */ case 0x01: /* atoms */ /* check that the content is really 0-terminated */ if ( value < bdf->strings_size && ft_memchr( bdf->strings + value, 0, bdf->strings_size ) ) { aprop->type = BDF_PROPERTY_TYPE_ATOM; aprop->u.atom = (const char*)bdf->strings + value; error = FT_Err_Ok; goto Exit; } break; case 0x02: aprop->type = BDF_PROPERTY_TYPE_INTEGER; aprop->u.integer = (FT_Int32)value; error = FT_Err_Ok; goto Exit; case 0x03: aprop->type = BDF_PROPERTY_TYPE_CARDINAL; aprop->u.cardinal = value; error = FT_Err_Ok; goto Exit; default: ; } } } p += 10; } Exit: return error; }
size_t ft_memlen(const void *s, int c, size_t n) { return (ft_memchr(s, c, n) - s); }
T1_Get_Private_Dict( T1_Parser parser, PSAux_Service psaux ) { FT_Stream stream = parser->stream; FT_Memory memory = parser->root.memory; FT_Error error = FT_Err_Ok; FT_ULong size; if ( parser->in_pfb ) { /* in the case of the PFB format, the private dictionary can be */ /* made of several segments. We thus first read the number of */ /* segments to compute the total size of the private dictionary */ /* then re-read them into memory. */ FT_ULong start_pos = FT_STREAM_POS(); FT_UShort tag; parser->private_len = 0; for (;;) { error = read_pfb_tag( stream, &tag, &size ); if ( error ) goto Fail; if ( tag != 0x8002U ) break; parser->private_len += size; if ( FT_STREAM_SKIP( size ) ) goto Fail; } /* Check that we have a private dictionary there */ /* and allocate private dictionary buffer */ if ( parser->private_len == 0 ) { FT_ERROR(( "T1_Get_Private_Dict:" " invalid private dictionary section\n" )); error = FT_THROW( Invalid_File_Format ); goto Fail; } if ( FT_STREAM_SEEK( start_pos ) || FT_ALLOC( parser->private_dict, parser->private_len ) ) goto Fail; parser->private_len = 0; for (;;) { error = read_pfb_tag( stream, &tag, &size ); if ( error || tag != 0x8002U ) { error = FT_Err_Ok; break; } if ( FT_STREAM_READ( parser->private_dict + parser->private_len, size ) ) goto Fail; parser->private_len += size; } } else { /* We have already `loaded' the whole PFA font file into memory; */ /* if this is a memory resource, allocate a new block to hold */ /* the private dict. Otherwise, simply overwrite into the base */ /* dictionary block in the heap. */ /* first of all, look at the `eexec' keyword */ FT_Byte* cur = parser->base_dict; FT_Byte* limit = cur + parser->base_len; FT_Byte c; FT_Pointer pos_lf; FT_Bool test_cr; Again: for (;;) { c = cur[0]; if ( c == 'e' && cur + 9 < limit ) /* 9 = 5 letters for `eexec' + */ /* whitespace + 4 chars */ { if ( cur[1] == 'e' && cur[2] == 'x' && cur[3] == 'e' && cur[4] == 'c' ) break; } cur++; if ( cur >= limit ) { FT_ERROR(( "T1_Get_Private_Dict:" " could not find `eexec' keyword\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } } /* check whether `eexec' was real -- it could be in a comment */ /* or string (as e.g. in u003043t.gsf from ghostscript) */ parser->root.cursor = parser->base_dict; /* set limit to `eexec' + whitespace + 4 characters */ parser->root.limit = cur + 10; cur = parser->root.cursor; limit = parser->root.limit; while ( cur < limit ) { if ( *cur == 'e' && strncmp( (char*)cur, "eexec", 5 ) == 0 ) goto Found; T1_Skip_PS_Token( parser ); if ( parser->root.error ) break; T1_Skip_Spaces ( parser ); cur = parser->root.cursor; } /* we haven't found the correct `eexec'; go back and continue */ /* searching */ cur = limit; limit = parser->base_dict + parser->base_len; goto Again; /* now determine where to write the _encrypted_ binary private */ /* dictionary. We overwrite the base dictionary for disk-based */ /* resources and allocate a new block otherwise */ Found: parser->root.limit = parser->base_dict + parser->base_len; T1_Skip_PS_Token( parser ); cur = parser->root.cursor; limit = parser->root.limit; /* According to the Type 1 spec, the first cipher byte must not be */ /* an ASCII whitespace character code (blank, tab, carriage return */ /* or line feed). We have seen Type 1 fonts with two line feed */ /* characters... So skip now all whitespace character codes. */ /* */ /* On the other hand, Adobe's Type 1 parser handles fonts just */ /* fine that are violating this limitation, so we add a heuristic */ /* test to stop at \r only if it is not used for EOL. */ pos_lf = ft_memchr( cur, '\n', (size_t)( limit - cur ) ); test_cr = FT_BOOL( !pos_lf || pos_lf > ft_memchr( cur, '\r', (size_t)( limit - cur ) ) ); while ( cur < limit && ( *cur == ' ' || *cur == '\t' || (test_cr && *cur == '\r' ) || *cur == '\n' ) ) ++cur; if ( cur >= limit ) { FT_ERROR(( "T1_Get_Private_Dict:" " `eexec' not properly terminated\n" )); error = FT_THROW( Invalid_File_Format ); goto Exit; } size = parser->base_len - (FT_ULong)( cur - parser->base_dict ); if ( parser->in_memory ) { /* note that we allocate one more byte to put a terminating `0' */ if ( FT_ALLOC( parser->private_dict, size + 1 ) ) goto Fail; parser->private_len = size; } else { parser->single_block = 1; parser->private_dict = parser->base_dict; parser->private_len = size; parser->base_dict = NULL; parser->base_len = 0; } /* now determine whether the private dictionary is encoded in binary */ /* or hexadecimal ASCII format -- decode it accordingly */ /* we need to access the next 4 bytes (after the final whitespace */ /* following the `eexec' keyword); if they all are hexadecimal */ /* digits, then we have a case of ASCII storage */ if ( cur + 3 < limit && ft_isxdigit( cur[0] ) && ft_isxdigit( cur[1] ) && ft_isxdigit( cur[2] ) && ft_isxdigit( cur[3] ) ) { /* ASCII hexadecimal encoding */ FT_ULong len; parser->root.cursor = cur; (void)psaux->ps_parser_funcs->to_bytes( &parser->root, parser->private_dict, parser->private_len, &len, 0 ); parser->private_len = len; /* put a safeguard */ parser->private_dict[len] = '\0'; } else /* binary encoding -- copy the private dict */ FT_MEM_MOVE( parser->private_dict, cur, size ); } /* we now decrypt the encoded binary private dictionary */ psaux->t1_decrypt( parser->private_dict, parser->private_len, 55665U ); if ( parser->private_len < 4 ) { FT_ERROR(( "T1_Get_Private_Dict:" " invalid private dictionary section\n" )); error = FT_THROW( Invalid_File_Format ); goto Fail; } /* replace the four random bytes at the beginning with whitespace */ parser->private_dict[0] = ' '; parser->private_dict[1] = ' '; parser->private_dict[2] = ' '; parser->private_dict[3] = ' '; parser->root.base = parser->private_dict; parser->root.cursor = parser->private_dict; parser->root.limit = parser->root.cursor + parser->private_len; Fail: Exit: return error; }
char *ft_t_strchr(t_str *str, char c) { return (ft_memchr(str->s, c, str->l)); }