1 /* 2 * Copyright (c) 2012-2017, Robin Hahling 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * * Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * * Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * * Neither the name of the author nor the names of its contributors may be 16 * used to endorse or promote products derived from this software without 17 * specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef H_UTIL 33 #define H_UTIL 34 /* 35 * util.h 36 * 37 * Util functions 38 */ 39 #include <inttypes.h> 40 41 #include "extern.h" 42 #include "list.h" 43 #include "platform/services.h" 44 45 /* function declaration */ 46 int imax(int a, int b); 47 char * strtrim(char *str); 48 char * shortenstr(char *str, int len); 49 char * sanitizestr(const char *str); 50 int humanize(double *n); 51 int humanize_i(uint64_t *n); 52 void print_unit(int i, int mode); 53 double cvrt(double n); 54 int fsfilter(const char *fs, const char *filter, int nm); 55 int cmp(struct fsmntinfo *a, struct fsmntinfo *b); 56 struct fsmntinfo * msort(struct fsmntinfo *fmi); 57 int getttywidth(void); 58 void init_maxwidths(void); 59 int get_req_width(double fs_size); 60 void update_maxwidth(struct fsmntinfo *fmi); 61 void auto_adjust(int tty_width); 62 char * fetchdate(void); 63 const char * colortostr(int color); 64 int colortoint(const char *col); 65 int chk_html_colorcode(const char *color); 66 int is_pseudofs(const char *type); 67 int is_remotefs(const char *type); 68 69 #endif /* ndef UTIL_H */ 70