diff options
author | Sergei Golubchik <sergii@pisem.net> | 2011-11-22 18:04:38 +0100 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2011-11-22 18:04:38 +0100 |
commit | d2755a2c9c109ddb4e2e0c9feda89431a6c4fd50 (patch) | |
tree | c6e4678908c750d7f558e98cedc349aa1d350892 /mysys | |
parent | af32b02c06f32a89dc9f52e556bc5dd3bf49c19e (diff) | |
parent | 42221abaed700f6dc5d280b462755851780e8487 (diff) | |
download | mariadb-git-d2755a2c9c109ddb4e2e0c9feda89431a6c4fd50.tar.gz |
5.3->5.5 merge
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/ma_dyncol.c | 129 | ||||
-rw-r--r-- | mysys/mf_iocache.c | 10 | ||||
-rw-r--r-- | mysys/my_bitmap.c | 90 | ||||
-rw-r--r-- | mysys/my_gethwaddr.c | 182 | ||||
-rw-r--r-- | mysys/my_getopt.c | 6 | ||||
-rw-r--r-- | mysys/my_init.c | 1 | ||||
-rw-r--r-- | mysys/my_malloc.c | 6 | ||||
-rw-r--r-- | mysys/my_open.c | 11 | ||||
-rw-r--r-- | mysys/my_pread.c | 34 | ||||
-rw-r--r-- | mysys/my_read.c | 8 | ||||
-rw-r--r-- | mysys/my_static.c | 2 | ||||
-rw-r--r-- | mysys/my_write.c | 11 | ||||
-rw-r--r-- | mysys/thr_mutex.c | 1 |
13 files changed, 287 insertions, 204 deletions
diff --git a/mysys/ma_dyncol.c b/mysys/ma_dyncol.c index 0901fe6bea1..c717f69c3e5 100644 --- a/mysys/ma_dyncol.c +++ b/mysys/ma_dyncol.c @@ -238,7 +238,7 @@ dynamic_column_uint_read(DYNAMIC_COLUMN_VALUE *store_it_here, for (i= 0; i < length; i++) value+= ((ulonglong)data[i]) << (i*8); - store_it_here->ulong_value= value; + store_it_here->x.ulong_value= value; return ER_DYNCOL_OK; } @@ -297,12 +297,12 @@ dynamic_column_sint_read(DYNAMIC_COLUMN_VALUE *store_it_here, { ulonglong val; dynamic_column_uint_read(store_it_here, data, length); - val= store_it_here->ulong_value; + val= store_it_here->x.ulong_value; if (val & 1) val= (val >> 1) ^ ULL(0xffffffffffffffff); else val>>= 1; - store_it_here->long_value= (longlong) val; + store_it_here->x.long_value= (longlong) val; return ER_DYNCOL_OK; } @@ -324,30 +324,30 @@ dynamic_column_value_len(DYNAMIC_COLUMN_VALUE *value) case DYN_COL_NULL: return 0; case DYN_COL_INT: - return dynamic_column_sint_bytes(value->long_value); + return dynamic_column_sint_bytes(value->x.long_value); case DYN_COL_UINT: - return dynamic_column_uint_bytes(value->ulong_value); + return dynamic_column_uint_bytes(value->x.ulong_value); case DYN_COL_DOUBLE: return 8; case DYN_COL_STRING: - return (dynamic_column_var_uint_bytes(value->charset->number) + - value->string_value.length); + return (dynamic_column_var_uint_bytes(value->x.string.charset->number) + + value->x.string.value.length); case DYN_COL_DECIMAL: { - int precision= value->decimal_value.intg + value->decimal_value.frac; - int scale= value->decimal_value.frac; + int precision= value->x.decimal.value.intg + value->x.decimal.value.frac; + int scale= value->x.decimal.value.frac; - if (precision == 0 || decimal_is_zero(&value->decimal_value)) + if (precision == 0 || decimal_is_zero(&value->x.decimal.value)) { /* This is here to simplify dynamic_column_decimal_store() */ - value->decimal_value.intg= value->decimal_value.frac= 0; + value->x.decimal.value.intg= value->x.decimal.value.frac= 0; return 0; } /* Check if legal decimal; This is needed to not get an assert in decimal_bin_size(). However this should be impossible as all decimals entered here should be valid and we have the special check - above to handle the unlikely but possible case that decimal_value.intg + above to handle the unlikely but possible case that decimal.value.intg and decimal.frac is 0. */ if (scale < 0 || precision <= 0) @@ -355,8 +355,8 @@ dynamic_column_value_len(DYNAMIC_COLUMN_VALUE *value) DBUG_ASSERT(0); /* Impossible */ return (size_t) ~0; } - return (dynamic_column_var_uint_bytes(value->decimal_value.intg) + - dynamic_column_var_uint_bytes(value->decimal_value.frac) + + return (dynamic_column_var_uint_bytes(value->x.decimal.value.intg) + + dynamic_column_var_uint_bytes(value->x.decimal.value.frac) + decimal_bin_size(precision, scale)); } case DYN_COL_DATETIME: @@ -410,7 +410,7 @@ dynamic_column_double_read(DYNAMIC_COLUMN_VALUE *store_it_here, { if (length != 8) return ER_DYNCOL_FORMAT; - float8get(store_it_here->double_value, data); + float8get(store_it_here->x.double_value, data); return ER_DYNCOL_OK; } @@ -455,12 +455,12 @@ dynamic_column_string_read(DYNAMIC_COLUMN_VALUE *store_it_here, uint charset_nr= (uint)dynamic_column_var_uint_get(data, length, &len); if (len == 0) /* Wrong packed number */ return ER_DYNCOL_FORMAT; - store_it_here->charset= get_charset(charset_nr, MYF(MY_WME)); - if (store_it_here->charset == NULL) + store_it_here->x.string.charset= get_charset(charset_nr, MYF(MY_WME)); + if (store_it_here->x.string.charset == NULL) return ER_DYNCOL_UNKNOWN_CHARSET; data+= len; - store_it_here->string_value.length= (length-= len); - store_it_here->string_value.str= (char*) data; + store_it_here->x.string.value.length= (length-= len); + store_it_here->x.string.value.str= (char*) data; return ER_DYNCOL_OK; } @@ -508,11 +508,11 @@ dynamic_column_decimal_store(DYNAMIC_COLUMN *str, void dynamic_column_prepare_decimal(DYNAMIC_COLUMN_VALUE *value) { - value->decimal_value.buf= value->decimal_buffer; - value->decimal_value.len= DECIMAL_BUFF_LENGTH; + value->x.decimal.value.buf= value->x.decimal.buffer; + value->x.decimal.value.len= DECIMAL_BUFF_LENGTH; /* just to be safe */ value->type= DYN_COL_DECIMAL; - decimal_make_zero(&value->decimal_value); + decimal_make_zero(&value->x.decimal.value); } @@ -553,7 +553,7 @@ dynamic_column_decimal_read(DYNAMIC_COLUMN_VALUE *store_it_here, (int) (length - intg_len - frac_len)) return ER_DYNCOL_FORMAT; - if (bin2decimal(data, &store_it_here->decimal_value, precision, scale) != + if (bin2decimal(data, &store_it_here->x.decimal.value, precision, scale) != E_DEC_OK) return ER_DYNCOL_FORMAT; return ER_DYNCOL_OK; @@ -607,14 +607,14 @@ dynamic_column_date_time_read(DYNAMIC_COLUMN_VALUE *store_it_here, */ if (length != 9) goto err; - store_it_here->time_value.time_type= MYSQL_TIMESTAMP_DATETIME; + store_it_here->x.time_value.time_type= MYSQL_TIMESTAMP_DATETIME; if ((rc= dynamic_column_date_read_internal(store_it_here, data, 3)) || (rc= dynamic_column_time_read_internal(store_it_here, data + 3, 6))) goto err; return ER_DYNCOL_OK; err: - store_it_here->time_value.time_type= MYSQL_TIMESTAMP_ERROR; + store_it_here->x.time_value.time_type= MYSQL_TIMESTAMP_ERROR; return rc; } @@ -682,9 +682,9 @@ static enum enum_dyncol_func_result dynamic_column_time_read(DYNAMIC_COLUMN_VALUE *store_it_here, uchar *data, size_t length) { - store_it_here->time_value.year= store_it_here->time_value.month= - store_it_here->time_value.day= 0; - store_it_here->time_value.time_type= MYSQL_TIMESTAMP_TIME; + store_it_here->x.time_value.year= store_it_here->x.time_value.month= + store_it_here->x.time_value.day= 0; + store_it_here->x.time_value.time_type= MYSQL_TIMESTAMP_TIME; return dynamic_column_time_read_internal(store_it_here, data, length); } @@ -709,23 +709,23 @@ dynamic_column_time_read_internal(DYNAMIC_COLUMN_VALUE *store_it_here, 1123456789012345612345612345678901234567890 <123456><123456><123456><123456><123456><123456> */ - store_it_here->time_value.second_part= (data[0] | + store_it_here->x.time_value.second_part= (data[0] | (data[1] << 8) | ((data[2] & 0xf) << 16)); - store_it_here->time_value.second= ((data[2] >> 4) | + store_it_here->x.time_value.second= ((data[2] >> 4) | ((data[3] & 0x3) << 4)); - store_it_here->time_value.minute= (data[3] >> 2); - store_it_here->time_value.hour= (((((uint)data[5]) & 0x3 ) << 8) | data[4]); - store_it_here->time_value.neg= ((data[5] & 0x4) ? 1 : 0); - if (store_it_here->time_value.second > 59 || - store_it_here->time_value.minute > 59 || - store_it_here->time_value.hour > 838 || - store_it_here->time_value.second_part > 999999) + store_it_here->x.time_value.minute= (data[3] >> 2); + store_it_here->x.time_value.hour= (((((uint)data[5]) & 0x3 ) << 8) | data[4]); + store_it_here->x.time_value.neg= ((data[5] & 0x4) ? 1 : 0); + if (store_it_here->x.time_value.second > 59 || + store_it_here->x.time_value.minute > 59 || + store_it_here->x.time_value.hour > 838 || + store_it_here->x.time_value.second_part > 999999) goto err; return ER_DYNCOL_OK; err: - store_it_here->time_value.time_type= MYSQL_TIMESTAMP_ERROR; + store_it_here->x.time_value.time_type= MYSQL_TIMESTAMP_ERROR; return ER_DYNCOL_FORMAT; } @@ -783,12 +783,12 @@ static enum enum_dyncol_func_result dynamic_column_date_read(DYNAMIC_COLUMN_VALUE *store_it_here, uchar *data, size_t length) { - store_it_here->time_value.neg= 0; - store_it_here->time_value.second_part= 0; - store_it_here->time_value.hour= 0; - store_it_here->time_value.minute= 0; - store_it_here->time_value.second= 0; - store_it_here->time_value.time_type= MYSQL_TIMESTAMP_DATE; + store_it_here->x.time_value.neg= 0; + store_it_here->x.time_value.second_part= 0; + store_it_here->x.time_value.hour= 0; + store_it_here->x.time_value.minute= 0; + store_it_here->x.time_value.second= 0; + store_it_here->x.time_value.time_type= MYSQL_TIMESTAMP_DATE; return dynamic_column_date_read_internal(store_it_here, data, length); } @@ -814,19 +814,19 @@ dynamic_column_date_read_internal(DYNAMIC_COLUMN_VALUE *store_it_here, 12345678901234123412345 <123456><123456><123456> */ - store_it_here->time_value.day= (data[0] & 0x1f); - store_it_here->time_value.month= (((data[1] & 0x1) << 3) | + store_it_here->x.time_value.day= (data[0] & 0x1f); + store_it_here->x.time_value.month= (((data[1] & 0x1) << 3) | (data[0] >> 5)); - store_it_here->time_value.year= ((((uint)data[2]) << 7) | + store_it_here->x.time_value.year= ((((uint)data[2]) << 7) | (data[1] >> 1)); - if (store_it_here->time_value.day > 31 || - store_it_here->time_value.month > 12 || - store_it_here->time_value.year > 9999) + if (store_it_here->x.time_value.day > 31 || + store_it_here->x.time_value.month > 12 || + store_it_here->x.time_value.year > 9999) goto err; return ER_DYNCOL_OK; err: - store_it_here->time_value.time_type= MYSQL_TIMESTAMP_ERROR; + store_it_here->x.time_value.time_type= MYSQL_TIMESTAMP_ERROR; return ER_DYNCOL_FORMAT; } @@ -845,25 +845,25 @@ data_store(DYNAMIC_COLUMN *str, DYNAMIC_COLUMN_VALUE *value) { switch (value->type) { case DYN_COL_INT: - return dynamic_column_sint_store(str, value->long_value); + return dynamic_column_sint_store(str, value->x.long_value); case DYN_COL_UINT: - return dynamic_column_uint_store(str, value->ulong_value); + return dynamic_column_uint_store(str, value->x.ulong_value); case DYN_COL_DOUBLE: - return dynamic_column_double_store(str, value->double_value); + return dynamic_column_double_store(str, value->x.double_value); case DYN_COL_STRING: - return dynamic_column_string_store(str, &value->string_value, - value->charset); + return dynamic_column_string_store(str, &value->x.string.value, + value->x.string.charset); case DYN_COL_DECIMAL: - return dynamic_column_decimal_store(str, &value->decimal_value); + return dynamic_column_decimal_store(str, &value->x.decimal.value); case DYN_COL_DATETIME: /* date+time in bits: 14 + 4 + 5 + 5 + 6 + 6 40bits = 5 bytes */ - return dynamic_column_date_time_store(str, &value->time_value); + return dynamic_column_date_time_store(str, &value->x.time_value); case DYN_COL_DATE: /* date in dits: 14 + 4 + 5 = 23bits ~= 3bytes*/ - return dynamic_column_date_store(str, &value->time_value); + return dynamic_column_date_store(str, &value->x.time_value); case DYN_COL_TIME: /* time in bits: 5 + 6 + 6 = 17bits ~= 3bytes*/ - return dynamic_column_time_store(str, &value->time_value); + return dynamic_column_time_store(str, &value->x.time_value); case DYN_COL_NULL: break; /* Impossible */ } @@ -1741,11 +1741,10 @@ dynamic_column_update_many(DYNAMIC_COLUMN *str, uint i, j, k; uint new_column_count, column_count, not_null; enum enum_dyncol_func_result rc; - int header_delta, header_delta_sign, data_delta_sign; + int header_delta; size_t offset_size, entry_size, header_size, data_size; size_t new_offset_size, new_entry_size, new_header_size, new_data_size; size_t max_offset; - my_bool copy; if (add_column_count == 0) return ER_DYNCOL_OK; @@ -1876,7 +1875,7 @@ dynamic_column_update_many(DYNAMIC_COLUMN *str, if (plan[i].val->type == DYN_COL_NULL) { - plan[i].act= PLAN_NOP; /* Mark entry to be skiped */ + plan[i].act= PLAN_NOP; /* Mark entry to be skiped */ } else { @@ -1913,17 +1912,17 @@ dynamic_column_update_many(DYNAMIC_COLUMN *str, goto end; } +#ifdef NOT_IMPLEMENTED /* if (new_offset_size != offset_size) then we have to rewrite header */ header_delta_sign= new_offset_size - offset_size; data_delta_sign= 0; - copy= FALSE; for (i= 0; i < add_column_count; i++) { /* This is the check for increasing/decreasing */ DELTA_CHECK(header_delta_sign, plan[i].hdelta, copy); DELTA_CHECK(data_delta_sign, plan[i].ddelta, copy); } - +#endif calc_param(&new_entry_size, &new_header_size, new_offset_size, new_column_count); diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c index 908f5c65cf7..c84a41bbec9 100644 --- a/mysys/mf_iocache.c +++ b/mysys/mf_iocache.c @@ -168,11 +168,9 @@ int init_io_cache(IO_CACHE *info, File file, size_t cachesize, if ((pos == (my_off_t) -1) && (my_errno == ESPIPE)) { /* - This kind of object doesn't support seek() or tell(). Don't set a - flag that will make us again try to seek() later and fail. - */ - info->seek_not_done= 0; - /* + This kind of object doesn't support seek() or tell(). Don't set a + seek_not_done that will make us again try to seek() later and fail. + Additionally, if we're supposed to start somewhere other than the the beginning of whatever this file is, then somebody made a bad assumption. @@ -1755,7 +1753,7 @@ int my_b_flush_io_cache(IO_CACHE *info, */ if (!append_cache && info->seek_not_done) { /* File touched, do seek */ - if (mysql_file_seek(info->file, pos_in_file, MY_SEEK_SET, MYF(0)) == + if (mysql_file_seek(info->file, pos_in_file, MY_SEEK_SET, MYF(info->myflags & MY_WME)) == MY_FILEPOS_ERROR) { UNLOCK_APPEND_BUFFER; diff --git a/mysys/my_bitmap.c b/mysys/my_bitmap.c index 414d5acaaf0..8328efea8ac 100644 --- a/mysys/my_bitmap.c +++ b/mysys/my_bitmap.c @@ -96,6 +96,44 @@ void create_last_word_mask(MY_BITMAP *map) } +static inline my_bitmap_map last_word_mask(uint bit) +{ + my_bitmap_map last_word_mask; + uint n_bits= bit + 1; + unsigned char const mask= invers_last_byte_mask(n_bits); + + /* + The first bytes are to be set to zero since they represent real bits + in the bitvector. The last bytes are set to 0xFF since they represent + bytes not used by the bitvector. Finally the last byte contains bits + as set by the mask above. + */ + unsigned char *ptr= (unsigned char*)&last_word_mask; + + switch ((n_bits + 7)/8 & 3) { + case 1: + last_word_mask= ~0U; + ptr[0]= mask; + break; + case 2: + last_word_mask= ~0U; + ptr[0]= 0; + ptr[1]= mask; + break; + case 3: + last_word_mask= 0U; + ptr[2]= mask; + ptr[3]= 0xFFU; + break; + case 0: + last_word_mask= 0U; + ptr[3]= mask; + break; + } + return last_word_mask; +} + + static inline void bitmap_lock(MY_BITMAP *map __attribute__((unused))) { if (map->mutex) @@ -380,6 +418,58 @@ void bitmap_intersect(MY_BITMAP *map, const MY_BITMAP *map2) } } + +/* + Check if there is some bit index between start_bit and end_bit, such that + this is bit is set for all bitmaps in bitmap_list. + + SYNOPSIS + bitmap_exists_intersection() + bitmpap_array [in] a set of MY_BITMAPs + bitmap_count [in] number of elements in bitmpap_array + start_bit [in] beginning (inclusive) of the range of bits to search + end_bit [in] end (inclusive) of the range of bits to search, must be + no bigger than the bits of the shortest bitmap. + + NOTES + This function assumes that for at least one of the bitmaps in bitmap_array all + bits outside the range [start_bit, end_bit] are 0. As a result is not + necessary to take care of the bits outside the range [start_bit, end_bit]. + + RETURN + TRUE if an intersecion exists + FALSE no intersection +*/ + +my_bool bitmap_exists_intersection(const MY_BITMAP **bitmap_array, + uint bitmap_count, + uint start_bit, uint end_bit) +{ + uint i, j, start_idx, end_idx; + my_bitmap_map cur_res; + + DBUG_ASSERT(bitmap_count && end_bit >= start_bit); + for (j= 0; j < bitmap_count; j++) + DBUG_ASSERT(end_bit < bitmap_array[j]->n_bits); + + start_idx= start_bit/8/sizeof(my_bitmap_map); + end_idx= end_bit/8/sizeof(my_bitmap_map); + + for (i= start_idx; i < end_idx; i++) + { + cur_res= ~0; + for (j= 0; cur_res && j < bitmap_count; j++) + cur_res &= bitmap_array[j]->bitmap[i]; + if (cur_res) + return TRUE; + } + cur_res= ~last_word_mask(end_bit); + for (j= 0; cur_res && j < bitmap_count; j++) + cur_res &= bitmap_array[j]->bitmap[end_idx]; + return cur_res != 0; +} + + /* True if union of bitmaps have all bits set */ my_bool bitmap_union_is_set_all(const MY_BITMAP *map1, const MY_BITMAP *map2) diff --git a/mysys/my_gethwaddr.c b/mysys/my_gethwaddr.c index 54823a7c5ca..4360daca6f8 100644 --- a/mysys/my_gethwaddr.c +++ b/mysys/my_gethwaddr.c @@ -1,4 +1,5 @@ -/* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2004, 2010, Oracle and/or its affiliates. + Copyright (c) 2011, Monty Program Ab This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,8 +22,17 @@ #ifndef MAIN -#ifdef __FreeBSD__ +static my_bool memcpy_and_test(uchar *to, uchar *from, uint len) +{ + uint i, res= 1; + + for (i= 0; i < len; i++) + if ((*to++= *from++)) + res= 0; + return res; +} +#if defined(__APPLE__) || defined(__FreeBSD__) #include <net/ethernet.h> #include <sys/sysctl.h> #include <net/route.h> @@ -32,11 +42,10 @@ my_bool my_gethwaddr(uchar *to) { size_t len; - char *buf, *next, *end; + uchar *buf, *next, *end, *addr; struct if_msghdr *ifm; struct sockaddr_dl *sdl; - int res=1, mib[6]={CTL_NET, AF_ROUTE, 0, AF_LINK, NET_RT_IFLIST, 0}; - char zero_array[ETHER_ADDR_LEN] = {0}; + int res= 1, mib[6]= {CTL_NET, AF_ROUTE, 0, AF_LINK, NET_RT_IFLIST, 0}; if (sysctl(mib, 6, NULL, &len, NULL, 0) == -1) goto err; @@ -52,9 +61,9 @@ my_bool my_gethwaddr(uchar *to) ifm = (struct if_msghdr *)next; if (ifm->ifm_type == RTM_IFINFO) { - sdl= (struct sockaddr_dl *)(ifm + 1); - memcpy(to, LLADDR(sdl), ETHER_ADDR_LEN); - res= memcmp(to, zero_array, ETHER_ADDR_LEN) ? 0 : 1; + sdl = (struct sockaddr_dl *)(ifm + 1); + addr= (uchar *)LLADDR(sdl); + res= memcpy_and_test(to, addr, ETHER_ADDR_LEN); } } @@ -62,140 +71,97 @@ err: return res; } -#elif __linux__ - +#elif defined(__linux__) || defined(__sun__) #include <net/if.h> #include <sys/ioctl.h> -#include <net/ethernet.h> +#include <net/if_arp.h> +#ifdef HAVE_SYS_SOCKIO_H +#include <sys/sockio.h> +#endif + +#define ETHER_ADDR_LEN 6 my_bool my_gethwaddr(uchar *to) { int fd, res= 1; - struct ifreq ifr; - char zero_array[ETHER_ADDR_LEN] = {0}; + struct ifreq ifr[32]; + struct ifconf ifc; + + ifc.ifc_req= ifr; + ifc.ifc_len= sizeof(ifr); fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd < 0) goto err; - bzero(&ifr, sizeof(ifr)); - strnmov(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name) - 1); - - do + if (ioctl(fd, SIOCGIFCONF, (char*)&ifc) >= 0) { - if (ioctl(fd, SIOCGIFHWADDR, &ifr) >= 0) + uint i; + for (i= 0; res && i < ifc.ifc_len / sizeof(ifr[0]); i++) { - memcpy(to, &ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN); - res= memcmp(to, zero_array, ETHER_ADDR_LEN) ? 0 : 1; +#ifdef SIOCGIFHWADDR + if (ioctl(fd, SIOCGIFHWADDR, &ifr[i]) >= 0) + res= memcpy_and_test(to, (uchar *)&ifr[i].ifr_hwaddr.sa_data, + ETHER_ADDR_LEN); +#else + /* + A bug in OpenSolaris prevents non-root from getting a mac address: + http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=4720634 + + Thus, we'll use an alternative method and extract the address from the + arp table. + */ + struct arpreq arpr; + arpr.arp_pa= ifr[i].ifr_addr; + + if (ioctl(fd, SIOCGARP, (char*)&arpr) >= 0) + res= memcpy_and_test(to, (uchar *)&arpr.arp_ha.sa_data, + ETHER_ADDR_LEN); +#endif } - } while (res && (errno == 0 || errno == ENODEV) && ifr.ifr_name[3]++ < '6'); + } close(fd); err: return res; } -#elif defined(__WIN__) - -/* - Workaround for BUG#32082 (Definition of VOID in my_global.h conflicts with - windows headers) -*/ -#ifdef VOID -#undef VOID -#define VOID void -#endif - +#elif defined(_WIN32) +#include <winsock2.h> #include <iphlpapi.h> -/* - The following typedef is for dynamically loading iphlpapi.dll / - GetAdaptersAddresses. Dynamic loading is used because - GetAdaptersAddresses is not available on Windows 2000 which MySQL - still supports. Static linking would cause an unresolved export. -*/ -typedef DWORD (WINAPI *pfnGetAdaptersAddresses)(IN ULONG Family, - IN DWORD Flags,IN PVOID Reserved, - OUT PIP_ADAPTER_ADDRESSES pAdapterAddresses, - IN OUT PULONG pOutBufLen); +#define ETHER_ADDR_LEN 6 -/* - my_gethwaddr - Windows version +my_bool my_gethwaddr(uchar *to) +{ + my_bool res= 1; - @brief Retrieve MAC address from network hardware + IP_ADAPTER_INFO *info= NULL; + ULONG info_len= 0; - @param[out] to MAC address exactly six bytes + if (GetAdaptersInfo(info, &info_len) != ERROR_BUFFER_OVERFLOW) + goto err; - @return Operation status - @retval 0 OK - @retval <>0 FAILED -*/ -my_bool my_gethwaddr(uchar *to) -{ - PIP_ADAPTER_ADDRESSES pAdapterAddresses; - PIP_ADAPTER_ADDRESSES pCurrAddresses; - IP_ADAPTER_ADDRESSES adapterAddresses; - ULONG address_len; - my_bool return_val= 1; - static pfnGetAdaptersAddresses fnGetAdaptersAddresses= - (pfnGetAdaptersAddresses)-1; - - if(fnGetAdaptersAddresses == (pfnGetAdaptersAddresses)-1) - { - /* Get the function from the DLL */ - fnGetAdaptersAddresses= (pfnGetAdaptersAddresses) - GetProcAddress(LoadLibrary("iphlpapi.dll"), - "GetAdaptersAddresses"); - } - if (!fnGetAdaptersAddresses) - return 1; /* failed to get function */ - address_len= sizeof (IP_ADAPTER_ADDRESSES); + info= alloca(info_len); - /* Get the required size for the address data. */ - if (fnGetAdaptersAddresses(AF_UNSPEC, 0, 0, &adapterAddresses, &address_len) - == ERROR_BUFFER_OVERFLOW) - { - pAdapterAddresses= my_malloc(address_len, 0); - if (!pAdapterAddresses) - return 1; /* error, alloc failed */ - } - else - pAdapterAddresses= &adapterAddresses; /* one is enough don't alloc */ + if (GetAdaptersInfo(info, &info_len) != NO_ERROR) + goto err; - /* Get the hardware info. */ - if (fnGetAdaptersAddresses(AF_UNSPEC, 0, 0, pAdapterAddresses, &address_len) - == NO_ERROR) + while (info && res) { - pCurrAddresses= pAdapterAddresses; - - while (pCurrAddresses) + if (info->Type == MIB_IF_TYPE_ETHERNET && + info->AddressLength == ETHER_ADDR_LEN) { - /* Look for ethernet cards. */ - if (pCurrAddresses->IfType == IF_TYPE_ETHERNET_CSMACD) - { - /* check for a good address */ - if (pCurrAddresses->PhysicalAddressLength < 6) - continue; /* bad address */ - - /* save 6 bytes of the address in the 'to' parameter */ - memcpy(to, pCurrAddresses->PhysicalAddress, 6); - - /* Network card found, we're done. */ - return_val= 0; - break; - } - pCurrAddresses= pCurrAddresses->Next; + res= memcpy_and_test(to, info->Address, ETHER_ADDR_LEN); } + info = info->Next; } - /* Clean up memory allocation. */ - if (pAdapterAddresses != &adapterAddresses) - my_free(pAdapterAddresses); - - return return_val; +err: + return res; } -#else /* __FreeBSD__ || __linux__ || __WIN__ */ +#else /* unsupported system */ /* just fail */ my_bool my_gethwaddr(uchar *to __attribute__((unused))) { @@ -214,7 +180,7 @@ int main(int argc __attribute__((unused)),char **argv) printf("my_gethwaddr failed with errno %d\n", errno); exit(1); } - for (i=0; i < sizeof(mac); i++) + for (i= 0; i < sizeof(mac); i++) { if (i) printf(":"); printf("%02x", mac[i]); diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index d9e34cbece6..ea09370280e 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -395,10 +395,12 @@ int handle_options(int *argc, char ***argv, */ (*argc)--; if (!optend || *optend == '1' || - !my_strcasecmp(&my_charset_latin1, optend, "true")) + !my_strcasecmp(&my_charset_latin1, optend, "true") || + !my_strcasecmp(&my_charset_latin1, optend, "on")) *((my_bool*) value)= (my_bool) 1; else if (*optend == '0' || - !my_strcasecmp(&my_charset_latin1, optend, "false")) + !my_strcasecmp(&my_charset_latin1, optend, "false") || + !my_strcasecmp(&my_charset_latin1, optend, "off")) *((my_bool*) value)= (my_bool) 0; else { diff --git a/mysys/my_init.c b/mysys/my_init.c index 6bbc11714ca..e366268936b 100644 --- a/mysys/my_init.c +++ b/mysys/my_init.c @@ -75,6 +75,7 @@ my_bool my_init(void) mysys_usage_id++; my_umask= 0660; /* Default umask for new files */ my_umask_dir= 0700; /* Default umask for new directories */ + my_global_flags= 0; /* Default creation of new files */ if ((str= getenv("UMASK")) != 0) diff --git a/mysys/my_malloc.c b/mysys/my_malloc.c index 2555c052fc3..24bccf37ece 100644 --- a/mysys/my_malloc.c +++ b/mysys/my_malloc.c @@ -30,6 +30,8 @@ void *my_malloc(size_t size, myf my_flags) void* point; DBUG_ENTER("my_malloc"); DBUG_PRINT("my",("size: %lu my_flags: %d", (ulong) size, my_flags)); + if (!(my_flags & (MY_WME | MY_FAE))) + my_flags|= my_global_flags; /* Safety */ if (!size) @@ -48,7 +50,9 @@ void *my_malloc(size_t size, myf my_flags) if (my_flags & MY_FAE) error_handler_hook=fatal_error_handler_hook; if (my_flags & (MY_FAE+MY_WME)) - my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG+ME_NOREFRESH),size); + my_error(EE_OUTOFMEMORY, + MYF(ME_BELL | ME_WAITTANG | ME_NOREFRESH | (my_flags & ME_JUST_INFO)), + size); DBUG_EXECUTE_IF("simulate_out_of_memory", DBUG_SET("-d,simulate_out_of_memory");); if (my_flags & MY_FAE) diff --git a/mysys/my_open.c b/mysys/my_open.c index cfbc9257aec..645d6709358 100644 --- a/mysys/my_open.c +++ b/mysys/my_open.c @@ -41,6 +41,8 @@ File my_open(const char *FileName, int Flags, myf MyFlags) DBUG_ENTER("my_open"); DBUG_PRINT("my",("Name: '%s' Flags: %d MyFlags: %d", FileName, Flags, MyFlags)); + if (!(MyFlags & (MY_WME | MY_FAE | MY_FFNF))) + MyFlags|= my_global_flags; #if defined(_WIN32) fd= my_win_open(FileName, Flags); #elif !defined(NO_OPEN_3) @@ -70,6 +72,8 @@ int my_close(File fd, myf MyFlags) int err; DBUG_ENTER("my_close"); DBUG_PRINT("my",("fd: %d MyFlags: %d",fd, MyFlags)); + if (!(MyFlags & (MY_WME | MY_FAE))) + MyFlags|= my_global_flags; mysql_mutex_lock(&THR_LOCK_open); #ifndef _WIN32 @@ -85,7 +89,8 @@ int my_close(File fd, myf MyFlags) DBUG_PRINT("error",("Got error %d on close",err)); my_errno=errno; if (MyFlags & (MY_FAE | MY_WME)) - my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG),my_filename(fd),errno); + my_error(EE_BADCLOSE, MYF(ME_BELL | ME_WAITTANG | (MyFlags & (ME_JUST_INFO | ME_NOREFRESH))), + my_filename(fd),errno); } if ((uint) fd < my_file_limit && my_file_info[fd].type != UNOPEN) { @@ -151,8 +156,8 @@ File my_register_filename(File fd, const char *FileName, enum file_type { if (my_errno == EMFILE) error_message_number= EE_OUT_OF_FILERESOURCES; - DBUG_PRINT("error",("print err: %d",error_message_number)); - my_error(error_message_number, MYF(ME_BELL+ME_WAITTANG), + my_error(error_message_number, + MYF(ME_BELL | ME_WAITTANG | (MyFlags & (ME_JUST_INFO | ME_NOREFRESH))), FileName, my_errno); } DBUG_RETURN(-1); diff --git a/mysys/my_pread.c b/mysys/my_pread.c index 4aa12eec33c..51b4c5f5599 100644 --- a/mysys/my_pread.c +++ b/mysys/my_pread.c @@ -51,8 +51,13 @@ size_t my_pread(File Filedes, uchar *Buffer, size_t Count, my_off_t offset, int error= 0; DBUG_ENTER("my_pread"); + DBUG_PRINT("my",("fd: %d Seek: %llu Buffer: %p Count: %lu MyFlags: %d", Filedes, (ulonglong)offset, Buffer, (ulong)Count, MyFlags)); + + if (!(MyFlags & (MY_WME | MY_FAE | MY_FNABP))) + MyFlags|= my_global_flags; + for (;;) { errno= 0; /* Linux, Windows don't reset this on EOF/success */ @@ -79,11 +84,13 @@ size_t my_pread(File Filedes, uchar *Buffer, size_t Count, my_off_t offset, } if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) { - if (readbytes == (size_t) -1) - my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG), - my_filename(Filedes),my_errno); - else if (MyFlags & (MY_NABP | MY_FNABP)) - my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), + if (readbytes == (size_t) -1) + my_error(EE_READ, + MYF(ME_BELL | ME_WAITTANG | (MyFlags & (ME_JUST_INFO | ME_NOREFRESH))), + my_filename(Filedes),my_errno); + else if (MyFlags & (MY_NABP | MY_FNABP)) + my_error(EE_EOFERR, + MYF(ME_BELL | ME_WAITTANG | (MyFlags & (ME_JUST_INFO | ME_NOREFRESH))), my_filename(Filedes),my_errno); } if (readbytes == (size_t) -1 || (MyFlags & (MY_FNABP | MY_NABP))) @@ -127,6 +134,8 @@ size_t my_pwrite(int Filedes, const uchar *Buffer, size_t Count, Filedes, (ulonglong)offset, Buffer, (ulong)Count, MyFlags)); errors= 0; written= 0; + if (!(MyFlags & (MY_WME | MY_FAE | MY_FNABP))) + MyFlags|= my_global_flags; for (;;) { @@ -159,20 +168,19 @@ size_t my_pwrite(int Filedes, const uchar *Buffer, size_t Count, if ((writtenbytes && writtenbytes != (size_t) -1) || my_errno == EINTR) continue; /* Retry */ #endif + + /* Don't give a warning if it's ok that we only write part of the data */ if (MyFlags & (MY_NABP | MY_FNABP)) { if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) - { - my_error(EE_WRITE, MYF(ME_BELL | ME_WAITTANG), + my_error(EE_WRITE, MYF(ME_BELL | ME_WAITTANG | (MyFlags & (ME_JUST_INFO | ME_NOREFRESH))), my_filename(Filedes),my_errno); - } - DBUG_RETURN(MY_FILE_ERROR); /* Error on read */ + DBUG_RETURN(MY_FILE_ERROR); /* Error on write */ } - else - break; /* Return bytes written */ + break; /* Return bytes written */ } DBUG_EXECUTE_IF("check", my_seek(Filedes, -1, SEEK_SET, MYF(0));); if (MyFlags & (MY_NABP | MY_FNABP)) - DBUG_RETURN(0); /* Want only errors */ - DBUG_RETURN(writtenbytes+written); /* purecov: inspected */ + DBUG_RETURN(0); /* Want only errors */ + DBUG_RETURN(writtenbytes+written); /* purecov: inspected */ } /* my_pwrite */ diff --git a/mysys/my_read.c b/mysys/my_read.c index ca5fbfaeef6..0afbf3773f3 100644 --- a/mysys/my_read.c +++ b/mysys/my_read.c @@ -40,6 +40,8 @@ size_t my_read(File Filedes, uchar *Buffer, size_t Count, myf MyFlags) DBUG_PRINT("my",("fd: %d Buffer: %p Count: %lu MyFlags: %d", Filedes, Buffer, (ulong) Count, MyFlags)); save_count= Count; + if (!(MyFlags & (MY_WME | MY_FAE | MY_FNABP))) + MyFlags|= my_global_flags; for (;;) { @@ -70,10 +72,12 @@ size_t my_read(File Filedes, uchar *Buffer, size_t Count, myf MyFlags) if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) { if (readbytes == (size_t) -1) - my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG), + my_error(EE_READ, + MYF(ME_BELL | ME_WAITTANG | (MyFlags & (ME_JUST_INFO | ME_NOREFRESH))), my_filename(Filedes),my_errno); else if (MyFlags & (MY_NABP | MY_FNABP)) - my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), + my_error(EE_EOFERR, + MYF(ME_BELL | ME_WAITTANG | (MyFlags & (ME_JUST_INFO | ME_NOREFRESH))), my_filename(Filedes),my_errno); } if (readbytes == (size_t) -1 || diff --git a/mysys/my_static.c b/mysys/my_static.c index ae32ae6387e..5b088704acc 100644 --- a/mysys/my_static.c +++ b/mysys/my_static.c @@ -33,6 +33,8 @@ ulong my_stream_opened=0,my_file_opened=0, my_tmp_file_created=0; ulong my_file_total_opened= 0; int my_umask=0664, my_umask_dir=0777; +myf my_global_flags= 0; +my_bool my_assert_on_error= 0; struct st_my_file_info my_file_info_default[MY_NFILE]; uint my_file_limit= MY_NFILE; struct st_my_file_info *my_file_info= my_file_info_default; diff --git a/mysys/my_write.c b/mysys/my_write.c index e873228620a..dc04b60f613 100644 --- a/mysys/my_write.c +++ b/mysys/my_write.c @@ -28,6 +28,8 @@ size_t my_write(File Filedes, const uchar *Buffer, size_t Count, myf MyFlags) DBUG_PRINT("my",("fd: %d Buffer: %p Count: %lu MyFlags: %d", Filedes, Buffer, (ulong) Count, MyFlags)); errors= 0; written= 0; + if (!(MyFlags & (MY_WME | MY_FAE | MY_FNABP))) + MyFlags|= my_global_flags; /* The behavior of write(fd, buf, 0) is not portable */ if (unlikely(!Count)) @@ -87,19 +89,20 @@ size_t my_write(File Filedes, const uchar *Buffer, size_t Count, myf MyFlags) else continue; /* Retry */ #endif + + /* Don't give a warning if it's ok that we only write part of the data */ if (MyFlags & (MY_NABP | MY_FNABP)) { if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) { - my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG), + my_error(EE_WRITE, MYF(ME_BELL | ME_WAITTANG | (MyFlags & (ME_JUST_INFO | ME_NOREFRESH))), my_filename(Filedes),my_errno); } DBUG_RETURN(MY_FILE_ERROR); /* Error on read */ } - else - break; /* Return bytes written */ + break; /* Return bytes written */ } if (MyFlags & (MY_NABP | MY_FNABP)) - DBUG_RETURN(0); /* Want only errors */ + DBUG_RETURN(0); /* Want only errors */ DBUG_RETURN(writtenbytes+written); } /* my_write */ diff --git a/mysys/thr_mutex.c b/mysys/thr_mutex.c index de222e7047f..d268fb618d5 100644 --- a/mysys/thr_mutex.c +++ b/mysys/thr_mutex.c @@ -836,6 +836,7 @@ static void print_deadlock_warning(safe_mutex_t *new_mutex, mutex_root->file, mutex_root->line)); } fflush(stderr); + DBUG_ASSERT(my_assert_on_error == 0); DBUG_VOID_RETURN; } |