summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
Diffstat (limited to 'mysys')
-rw-r--r--mysys/COPYING.LIB481
-rw-r--r--mysys/Makefile.am13
-rw-r--r--mysys/charset-def.c1
-rw-r--r--mysys/charset.c29
-rw-r--r--mysys/charset2html.c34
-rw-r--r--mysys/default.c8
-rw-r--r--mysys/hash.c8
-rw-r--r--mysys/mf_iocache.c11
-rw-r--r--mysys/mf_keycache.c6
-rw-r--r--mysys/mf_pack.c30
-rw-r--r--mysys/mf_soundex.c4
-rw-r--r--mysys/mf_tempdir.c4
-rw-r--r--mysys/mf_tempfile.c13
-rw-r--r--mysys/my_alloc.c66
-rw-r--r--mysys/my_div.c2
-rw-r--r--mysys/my_dup.c2
-rw-r--r--mysys/my_file.c147
-rw-r--r--mysys/my_fopen.c8
-rw-r--r--mysys/my_gethwaddr.c130
-rw-r--r--mysys/my_getopt.c23
-rw-r--r--mysys/my_getsystime.c48
-rw-r--r--mysys/my_handler.c81
-rw-r--r--mysys/my_init.c11
-rw-r--r--mysys/my_new.cc4
-rw-r--r--mysys/my_open.c4
-rw-r--r--mysys/my_static.c4
-rw-r--r--mysys/my_static.h2
-rw-r--r--mysys/my_tempnam.c11
-rw-r--r--mysys/my_thr_init.c2
-rw-r--r--mysys/mysys_priv.h5
-rw-r--r--mysys/test_fn.c3
-rw-r--r--mysys/tree.c26
32 files changed, 607 insertions, 614 deletions
diff --git a/mysys/COPYING.LIB b/mysys/COPYING.LIB
deleted file mode 100644
index eb685a5ec98..00000000000
--- a/mysys/COPYING.LIB
+++ /dev/null
@@ -1,481 +0,0 @@
- GNU LIBRARY GENERAL PUBLIC LICENSE
- Version 2, June 1991
-
- Copyright (C) 1991 Free Software Foundation, Inc.
- 675 Mass Ave, Cambridge, MA 02139, USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-[This is the first released version of the library GPL. It is
- numbered 2 because it goes with version 2 of the ordinary GPL.]
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-Licenses are intended to guarantee your freedom to share and change
-free software--to make sure the software is free for all its users.
-
- This license, the Library General Public License, applies to some
-specially designated Free Software Foundation software, and to any
-other libraries whose authors decide to use it. You can use it for
-your libraries, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if
-you distribute copies of the library, or if you modify it.
-
- For example, if you distribute copies of the library, whether gratis
-or for a fee, you must give the recipients all the rights that we gave
-you. You must make sure that they, too, receive or can get the source
-code. If you link a program with the library, you must provide
-complete object files to the recipients so that they can relink them
-with the library, after making changes to the library and recompiling
-it. And you must show them these terms so they know their rights.
-
- Our method of protecting your rights has two steps: (1) copyright
-the library, and (2) offer you this license which gives you legal
-permission to copy, distribute and/or modify the library.
-
- Also, for each distributor's protection, we want to make certain
-that everyone understands that there is no warranty for this free
-library. If the library is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original
-version, so that any problems introduced by others will not reflect on
-the original authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that companies distributing free
-software will individually obtain patent licenses, thus in effect
-transforming the program into proprietary software. To prevent this,
-we have made it clear that any patent must be licensed for everyone's
-free use or not licensed at all.
-
- Most GNU software, including some libraries, is covered by the ordinary
-GNU General Public License, which was designed for utility programs. This
-license, the GNU Library General Public License, applies to certain
-designated libraries. This license is quite different from the ordinary
-one; be sure to read it in full, and don't assume that anything in it is
-the same as in the ordinary license.
-
- The reason we have a separate public license for some libraries is that
-they blur the distinction we usually make between modifying or adding to a
-program and simply using it. Linking a program with a library, without
-changing the library, is in some sense simply using the library, and is
-analogous to running a utility program or application program. However, in
-a textual and legal sense, the linked executable is a combined work, a
-derivative of the original library, and the ordinary General Public License
-treats it as such.
-
- Because of this blurred distinction, using the ordinary General
-Public License for libraries did not effectively promote software
-sharing, because most developers did not use the libraries. We
-concluded that weaker conditions might promote sharing better.
-
- However, unrestricted linking of non-free programs would deprive the
-users of those programs of all benefit from the free status of the
-libraries themselves. This Library General Public License is intended to
-permit developers of non-free programs to use free libraries, while
-preserving your freedom as a user of such programs to change the free
-libraries that are incorporated in them. (We have not seen how to achieve
-this as regards changes in header files, but we have achieved it as regards
-changes in the actual functions of the Library.) The hope is that this
-will lead to faster development of free libraries.
-
- The precise terms and conditions for copying, distribution and
-modification follow. Pay close attention to the difference between a
-"work based on the library" and a "work that uses the library". The
-former contains code derived from the library, while the latter only
-works together with the library.
-
- Note that it is possible for a library to be covered by the ordinary
-General Public License rather than by this special one.
-
- GNU LIBRARY GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License Agreement applies to any software library which
-contains a notice placed by the copyright holder or other authorized
-party saying it may be distributed under the terms of this Library
-General Public License (also called "this License"). Each licensee is
-addressed as "you".
-
- A "library" means a collection of software functions and/or data
-prepared so as to be conveniently linked with application programs
-(which use some of those functions and data) to form executables.
-
- The "Library", below, refers to any such software library or work
-which has been distributed under these terms. A "work based on the
-Library" means either the Library or any derivative work under
-copyright law: that is to say, a work containing the Library or a
-portion of it, either verbatim or with modifications and/or translated
-straightforwardly into another language. (Hereinafter, translation is
-included without limitation in the term "modification".)
-
- "Source code" for a work means the preferred form of the work for
-making modifications to it. For a library, complete source code means
-all the source code for all modules it contains, plus any associated
-interface definition files, plus the scripts used to control compilation
-and installation of the library.
-
- Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running a program using the Library is not restricted, and output from
-such a program is covered only if its contents constitute a work based
-on the Library (independent of the use of the Library in a tool for
-writing it). Whether that is true depends on what the Library does
-and what the program that uses the Library does.
-
- 1. You may copy and distribute verbatim copies of the Library's
-complete source code as you receive it, in any medium, provided that
-you conspicuously and appropriately publish on each copy an
-appropriate copyright notice and disclaimer of warranty; keep intact
-all the notices that refer to this License and to the absence of any
-warranty; and distribute a copy of this License along with the
-Library.
-
- You may charge a fee for the physical act of transferring a copy,
-and you may at your option offer warranty protection in exchange for a
-fee.
-
- 2. You may modify your copy or copies of the Library or any portion
-of it, thus forming a work based on the Library, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) The modified work must itself be a software library.
-
- b) You must cause the files modified to carry prominent notices
- stating that you changed the files and the date of any change.
-
- c) You must cause the whole of the work to be licensed at no
- charge to all third parties under the terms of this License.
-
- d) If a facility in the modified Library refers to a function or a
- table of data to be supplied by an application program that uses
- the facility, other than as an argument passed when the facility
- is invoked, then you must make a good faith effort to ensure that,
- in the event an application does not supply such function or
- table, the facility still operates, and performs whatever part of
- its purpose remains meaningful.
-
- (For example, a function in a library to compute square roots has
- a purpose that is entirely well-defined independent of the
- application. Therefore, Subsection 2d requires that any
- application-supplied function or table used by this function must
- be optional: if the application does not supply it, the square
- root function must still compute square roots.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Library,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Library, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote
-it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Library.
-
-In addition, mere aggregation of another work not based on the Library
-with the Library (or with a work based on the Library) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may opt to apply the terms of the ordinary GNU General Public
-License instead of this License to a given copy of the Library. To do
-this, you must alter all the notices that refer to this License, so
-that they refer to the ordinary GNU General Public License, version 2,
-instead of to this License. (If a newer version than version 2 of the
-ordinary GNU General Public License has appeared, then you can specify
-that version instead if you wish.) Do not make any other change in
-these notices.
-
- Once this change is made in a given copy, it is irreversible for
-that copy, so the ordinary GNU General Public License applies to all
-subsequent copies and derivative works made from that copy.
-
- This option is useful when you wish to copy part of the code of
-the Library into a program that is not a library.
-
- 4. You may copy and distribute the Library (or a portion or
-derivative of it, under Section 2) in object code or executable form
-under the terms of Sections 1 and 2 above provided that you accompany
-it with the complete corresponding machine-readable source code, which
-must be distributed under the terms of Sections 1 and 2 above on a
-medium customarily used for software interchange.
-
- If distribution of object code is made by offering access to copy
-from a designated place, then offering equivalent access to copy the
-source code from the same place satisfies the requirement to
-distribute the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 5. A program that contains no derivative of any portion of the
-Library, but is designed to work with the Library by being compiled or
-linked with it, is called a "work that uses the Library". Such a
-work, in isolation, is not a derivative work of the Library, and
-therefore falls outside the scope of this License.
-
- However, linking a "work that uses the Library" with the Library
-creates an executable that is a derivative of the Library (because it
-contains portions of the Library), rather than a "work that uses the
-library". The executable is therefore covered by this License.
-Section 6 states terms for distribution of such executables.
-
- When a "work that uses the Library" uses material from a header file
-that is part of the Library, the object code for the work may be a
-derivative work of the Library even though the source code is not.
-Whether this is true is especially significant if the work can be
-linked without the Library, or if the work is itself a library. The
-threshold for this to be true is not precisely defined by law.
-
- If such an object file uses only numerical parameters, data
-structure layouts and accessors, and small macros and small inline
-functions (ten lines or less in length), then the use of the object
-file is unrestricted, regardless of whether it is legally a derivative
-work. (Executables containing this object code plus portions of the
-Library will still fall under Section 6.)
-
- Otherwise, if the work is a derivative of the Library, you may
-distribute the object code for the work under the terms of Section 6.
-Any executables containing that work also fall under Section 6,
-whether or not they are linked directly with the Library itself.
-
- 6. As an exception to the Sections above, you may also compile or
-link a "work that uses the Library" with the Library to produce a
-work containing portions of the Library, and distribute that work
-under terms of your choice, provided that the terms permit
-modification of the work for the customer's own use and reverse
-engineering for debugging such modifications.
-
- You must give prominent notice with each copy of the work that the
-Library is used in it and that the Library and its use are covered by
-this License. You must supply a copy of this License. If the work
-during execution displays copyright notices, you must include the
-copyright notice for the Library among them, as well as a reference
-directing the user to the copy of this License. Also, you must do one
-of these things:
-
- a) Accompany the work with the complete corresponding
- machine-readable source code for the Library including whatever
- changes were used in the work (which must be distributed under
- Sections 1 and 2 above); and, if the work is an executable linked
- with the Library, with the complete machine-readable "work that
- uses the Library", as object code and/or source code, so that the
- user can modify the Library and then relink to produce a modified
- executable containing the modified Library. (It is understood
- that the user who changes the contents of definitions files in the
- Library will not necessarily be able to recompile the application
- to use the modified definitions.)
-
- b) Accompany the work with a written offer, valid for at
- least three years, to give the same user the materials
- specified in Subsection 6a, above, for a charge no more
- than the cost of performing this distribution.
-
- c) If distribution of the work is made by offering access to copy
- from a designated place, offer equivalent access to copy the above
- specified materials from the same place.
-
- d) Verify that the user has already received a copy of these
- materials or that you have already sent this user a copy.
-
- For an executable, the required form of the "work that uses the
-Library" must include any data and utility programs needed for
-reproducing the executable from it. However, as a special exception,
-the source code distributed need not include anything that is normally
-distributed (in either source or binary form) with the major
-components (compiler, kernel, and so on) of the operating system on
-which the executable runs, unless that component itself accompanies
-the executable.
-
- It may happen that this requirement contradicts the license
-restrictions of other proprietary libraries that do not normally
-accompany the operating system. Such a contradiction means you cannot
-use both them and the Library together in an executable that you
-distribute.
-
- 7. You may place library facilities that are a work based on the
-Library side-by-side in a single library together with other library
-facilities not covered by this License, and distribute such a combined
-library, provided that the separate distribution of the work based on
-the Library and of the other library facilities is otherwise
-permitted, and provided that you do these two things:
-
- a) Accompany the combined library with a copy of the same work
- based on the Library, uncombined with any other library
- facilities. This must be distributed under the terms of the
- Sections above.
-
- b) Give prominent notice with the combined library of the fact
- that part of it is a work based on the Library, and explaining
- where to find the accompanying uncombined form of the same work.
-
- 8. You may not copy, modify, sublicense, link with, or distribute
-the Library except as expressly provided under this License. Any
-attempt otherwise to copy, modify, sublicense, link with, or
-distribute the Library is void, and will automatically terminate your
-rights under this License. However, parties who have received copies,
-or rights, from you under this License will not have their licenses
-terminated so long as such parties remain in full compliance.
-
- 9. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Library or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Library (or any work based on the
-Library), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Library or works based on it.
-
- 10. Each time you redistribute the Library (or any work based on the
-Library), the recipient automatically receives a license from the
-original licensor to copy, distribute, link with or modify the Library
-subject to these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
- 11. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Library at all. For example, if a patent
-license would not permit royalty-free redistribution of the Library by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Library.
-
-If any portion of this section is held invalid or unenforceable under any
-particular circumstance, the balance of the section is intended to apply,
-and the section as a whole is intended to apply in other circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 12. If the distribution and/or use of the Library is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Library under this License may add
-an explicit geographical distribution limitation excluding those countries,
-so that distribution is permitted only in or among countries not thus
-excluded. In such case, this License incorporates the limitation as if
-written in the body of this License.
-
- 13. The Free Software Foundation may publish revised and/or new
-versions of the Library General Public License from time to time.
-Such new versions will be similar in spirit to the present version,
-but may differ in detail to address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Library
-specifies a version number of this License which applies to it and
-"any later version", you have the option of following the terms and
-conditions either of that version or of any later version published by
-the Free Software Foundation. If the Library does not specify a
-license version number, you may choose any version ever published by
-the Free Software Foundation.
-
- 14. If you wish to incorporate parts of the Library into other free
-programs whose distribution conditions are incompatible with these,
-write to the author to ask for permission. For software which is
-copyrighted by the Free Software Foundation, write to the Free
-Software Foundation; we sometimes make exceptions for this. Our
-decision will be guided by the two goals of preserving the free status
-of all derivatives of our free software and of promoting the sharing
-and reuse of software generally.
-
- NO WARRANTY
-
- 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
-WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
-EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
-OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
-KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
-LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
-THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
- 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
-WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
-AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
-FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
-CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
-LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
-RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
-FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
-SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
-DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- Appendix: How to Apply These Terms to Your New Libraries
-
- If you develop a new library, and you want it to be of the greatest
-possible use to the public, we recommend making it free software that
-everyone can redistribute and change. You can do so by permitting
-redistribution under these terms (or, alternatively, under the terms of the
-ordinary General Public License).
-
- To apply these terms, attach the following notices to the library. It is
-safest to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least the
-"copyright" line and a pointer to where the full notice is found.
-
- <one line to give the library's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with this library; if not, write to the Free
- Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-Also add information on how to contact you by electronic and paper mail.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the library, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the
- library `Frob' (a library for tweaking knobs) written by James Random Hacker.
-
- <signature of Ty Coon>, 1 April 1990
- Ty Coon, President of Vice
-
-That's all there is to it!
diff --git a/mysys/Makefile.am b/mysys/Makefile.am
index bd508b8de12..d4290bbc49b 100644
--- a/mysys/Makefile.am
+++ b/mysys/Makefile.am
@@ -25,8 +25,8 @@ noinst_HEADERS = mysys_priv.h my_static.h \
my_os2cond.c my_os2dirsrch.c my_os2dirsrch.h \
my_os2dlfcn.c my_os2file64.c my_os2mutex.c \
my_os2thread.c my_os2tls.c
-libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c\
- mf_path.c mf_loadpath.c\
+libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c \
+ mf_path.c mf_loadpath.c my_file.c \
my_open.c my_create.c my_dup.c my_seek.c my_read.c \
my_pread.c my_write.c \
mf_keycache.c mf_keycaches.c my_crc32.c \
@@ -34,12 +34,12 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c\
mf_tempdir.c my_lock.c mf_brkhant.c my_alarm.c \
my_malloc.c my_realloc.c my_once.c mulalloc.c \
my_alloc.c safemalloc.c my_new.cc \
- my_fopen.c my_fstream.c \
+ my_fopen.c my_fstream.c my_getsystime.c \
my_error.c errors.c my_div.c my_messnc.c \
mf_format.c mf_same.c mf_dirname.c mf_fn_ext.c \
my_symlink.c my_symlink2.c \
mf_pack.c mf_unixpath.c mf_strip.c \
- mf_wcomp.c mf_wfile.c \
+ mf_wcomp.c mf_wfile.c my_gethwaddr.c \
mf_qsort.c mf_qsort2.c mf_sort.c \
ptr_cmp.c mf_radix.c queues.c \
tree.c list.c hash.c array.c string.c typelib.c \
@@ -110,5 +110,10 @@ charset2html$(EXEEXT): charset2html.c $(LIBRARIES)
testhash$(EXEEXT): testhash.c $(LIBRARIES)
$(LINK) $(FLAGS) -DMAIN $(srcdir)/testhash.c $(LDADD) $(LIBS)
+test_gethwaddr$(EXEEXT): my_gethwaddr.c $(LIBRARIES)
+ $(CP) $(srcdir)/my_gethwaddr.c ./test_gethwaddr.c
+ $(LINK) $(FLAGS) -DMAIN ./test_gethwaddr.c $(LDADD) $(LIBS)
+ $(RM) -f ./test_gethwaddr.c
+
# Don't update the files from bitkeeper
%::SCCS/s.%
diff --git a/mysys/charset-def.c b/mysys/charset-def.c
index 650431eaf76..a89cf866933 100644
--- a/mysys/charset-def.c
+++ b/mysys/charset-def.c
@@ -73,6 +73,7 @@ my_bool init_compiled_charsets(myf flags __attribute__((unused)))
#ifdef HAVE_CHARSET_ucs2
add_compiled_collation(&my_charset_ucs2_general_ci);
add_compiled_collation(&my_charset_ucs2_bin);
+ add_compiled_collation(&my_charset_ucs2_general_uca);
#endif
#ifdef HAVE_CHARSET_ujis
diff --git a/mysys/charset.c b/mysys/charset.c
index 5bf0ea972a5..80f62b06a3e 100644
--- a/mysys/charset.c
+++ b/mysys/charset.c
@@ -62,7 +62,7 @@ static void set_max_sort_char(CHARSET_INFO *cs)
if ((uchar) cs->sort_order[i] > max_char)
{
max_char=(uchar) cs->sort_order[i];
- cs->max_sort_char= (char) i;
+ cs->max_sort_char= i;
}
}
}
@@ -459,7 +459,9 @@ static my_bool init_available_charsets(myf myflags)
init_compiled_charsets(myflags);
/* Copy compiled charsets */
- for (cs=all_charsets; cs < all_charsets+255 ; cs++)
+ for (cs=all_charsets;
+ cs < all_charsets+array_elements(all_charsets)-1 ;
+ cs++)
{
if (*cs)
{
@@ -486,10 +488,11 @@ void free_charsets(void)
uint get_collation_number(const char *name)
{
CHARSET_INFO **cs;
- if (init_available_charsets(MYF(0))) /* If it isn't initialized */
- return 0;
+ init_available_charsets(MYF(0));
- for (cs= all_charsets; cs < all_charsets+255; ++cs)
+ for (cs= all_charsets;
+ cs < all_charsets+array_elements(all_charsets)-1 ;
+ cs++)
{
if ( cs[0] && cs[0]->name &&
!my_strcasecmp(&my_charset_latin1, cs[0]->name, name))
@@ -498,13 +501,15 @@ uint get_collation_number(const char *name)
return 0; /* this mimics find_type() */
}
+
uint get_charset_number(const char *charset_name, uint cs_flags)
{
CHARSET_INFO **cs;
- if (init_available_charsets(MYF(0))) /* If it isn't initialized */
- return 0;
+ init_available_charsets(MYF(0));
- for (cs= all_charsets; cs < all_charsets+255; ++cs)
+ for (cs= all_charsets;
+ cs < all_charsets+array_elements(all_charsets)-1 ;
+ cs++)
{
if ( cs[0] && cs[0]->csname && (cs[0]->state & cs_flags) &&
!my_strcasecmp(&my_charset_latin1, cs[0]->csname, charset_name))
@@ -517,8 +522,7 @@ uint get_charset_number(const char *charset_name, uint cs_flags)
const char *get_charset_name(uint charset_number)
{
CHARSET_INFO *cs;
- if (init_available_charsets(MYF(0))) /* If it isn't initialized */
- return "?";
+ init_available_charsets(MYF(0));
cs=all_charsets[charset_number];
if (cs && (cs->number == charset_number) && cs->name )
@@ -554,9 +558,12 @@ static CHARSET_INFO *get_internal_charset(uint cs_number, myf flags)
CHARSET_INFO *get_charset(uint cs_number, myf flags)
{
CHARSET_INFO *cs;
+ if (cs_number == default_charset_info->number)
+ return default_charset_info;
+
(void) init_available_charsets(MYF(0)); /* If it isn't initialized */
- if (!cs_number)
+ if (!cs_number || cs_number >= array_elements(all_charsets)-1)
return NULL;
cs=get_internal_charset(cs_number, flags);
diff --git a/mysys/charset2html.c b/mysys/charset2html.c
index 64021689bea..96862ff16a1 100644
--- a/mysys/charset2html.c
+++ b/mysys/charset2html.c
@@ -84,18 +84,30 @@ static void print_cs(CHARSET_INFO *cs)
printf("<TD>%02X",ch[i].srt);
printf("<TD>%s%s%s%s%s%s%s%s",
- ch[i].ctp & _U ? "U" : "",
- ch[i].ctp & _L ? "L" : "",
- ch[i].ctp & _NMR ? "N" : "",
- ch[i].ctp & _SPC ? "S" : "",
- ch[i].ctp & _PNT ? "P" : "",
- ch[i].ctp & _CTR ? "C" : "",
- ch[i].ctp & _B ? "B" : "",
- ch[i].ctp & _X ? "X" : "");
+ ch[i].ctp & _MY_U ? "U" : "",
+ ch[i].ctp & _MY_L ? "L" : "",
+ ch[i].ctp & _MY_NMR ? "N" : "",
+ ch[i].ctp & _MY_SPC ? "S" : "",
+ ch[i].ctp & _MY_PNT ? "P" : "",
+ ch[i].ctp & _MY_CTR ? "C" : "",
+ ch[i].ctp & _MY_B ? "B" : "",
+ ch[i].ctp & _MY_X ? "X" : "");
- printf("<TD>&#%d;",ch[i].uni);
- printf("<TD>&#%d;",ch[i].low);
- printf("<TD>&#%d;",ch[i].upp);
+ if ((ch[i].uni >= 0x80) && (ch[i].uni <= 0x9F))
+ {
+ /*
+ Control characters 0x0080..0x009F are dysplayed by some
+ browers as if they were letters. Don't print them to
+ avoid confusion.
+ */
+ printf("<TD>ctrl<TD>ctrl<TD>ctrl");
+ }
+ else
+ {
+ printf("<TD>&#%d;",ch[i].uni);
+ printf("<TD>&#%d;",ch[i].low);
+ printf("<TD>&#%d;",ch[i].upp);
+ }
printf("</TR>\n");
srt=ch[i].srt;
}
diff --git a/mysys/default.c b/mysys/default.c
index a01ed4dd39f..d09b0dd97af 100644
--- a/mysys/default.c
+++ b/mysys/default.c
@@ -450,23 +450,25 @@ static int search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc,
static char *remove_end_comment(char *ptr)
{
- char quote= 0;
+ char quote= 0; /* we are inside quote marks */
+ char escape= 0; /* symbol is protected by escape chagacter */
for (; *ptr; ptr++)
{
- if (*ptr == '\'' || *ptr == '\"')
+ if ((*ptr == '\'' || *ptr == '\"') && !escape)
{
if (!quote)
quote= *ptr;
else if (quote == *ptr)
quote= 0;
}
- /* We are not inside a comment */
+ /* We are not inside a string */
if (!quote && *ptr == '#')
{
*ptr= 0;
return ptr;
}
+ escape= (quote && *ptr == '\\' && !escape);
}
return ptr;
}
diff --git a/mysys/hash.c b/mysys/hash.c
index 4ef8847363f..b7be41a9058 100644
--- a/mysys/hash.c
+++ b/mysys/hash.c
@@ -122,7 +122,7 @@ static uint hash_rec_mask(HASH *hash,HASH_LINK *pos,uint buffmax,
-#ifndef __SUNPRO_C /* SUNPRO can't handle this */
+#if !defined(__SUNPRO_C) && !defined(__USLC__) /* broken compilers */
inline
#endif
unsigned int rec_hashnr(HASH *hash,const byte *record)
@@ -215,9 +215,9 @@ static int hashcmp(HASH *hash,HASH_LINK *pos,const byte *key,uint length)
{
uint rec_keylength;
byte *rec_key= (byte*) hash_key(hash,pos->data,&rec_keylength,1);
- return (length && length != rec_keylength) ||
- my_strnncoll(hash->charset, (uchar*) rec_key, rec_keylength,
- (uchar*) key, length);
+ return ((length && length != rec_keylength) ||
+ my_strnncoll(hash->charset, (uchar*) rec_key, rec_keylength,
+ (uchar*) key, length));
}
diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c
index f64dc5abf2d..530721a79ad 100644
--- a/mysys/mf_iocache.c
+++ b/mysys/mf_iocache.c
@@ -152,6 +152,7 @@ int init_io_cache(IO_CACHE *info, File file, uint cachesize,
info->alloced_buffer = 0;
info->buffer=0;
info->seek_not_done= test(file >= 0);
+ info->disk_writes= 0;
#ifdef THREAD
info->share=0;
#endif
@@ -506,7 +507,8 @@ static int lock_io_cache(IO_CACHE *info, my_off_t pos)
while (!s->active || s->active->pos_in_file < pos)
pthread_cond_wait(&s->cond, &s->mutex);
- if (s->total < total)
+ if (s->total < total &&
+ (!s->active || s->active->pos_in_file < pos))
return 1;
pthread_mutex_unlock(&s->mutex);
@@ -987,7 +989,7 @@ int my_b_append(register IO_CACHE *info, const byte *Buffer, uint Count)
Buffer+=rest_length;
Count-=rest_length;
info->write_pos+=rest_length;
- if (_flush_io_cache(info,0))
+ if (my_b_flush_io_cache(info,0))
{
unlock_append_buffer(info);
return 1;
@@ -1094,12 +1096,12 @@ int my_block_write(register IO_CACHE *info, const byte *Buffer, uint Count,
#endif
-int _flush_io_cache(IO_CACHE *info, int need_append_buffer_lock)
+int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock)
{
uint length;
my_bool append_cache;
my_off_t pos_in_file;
- DBUG_ENTER("_flush_io_cache");
+ DBUG_ENTER("my_b_flush_io_cache");
if (!(append_cache = (info->type == SEQ_READ_APPEND)))
need_append_buffer_lock=0;
@@ -1152,6 +1154,7 @@ int _flush_io_cache(IO_CACHE *info, int need_append_buffer_lock)
}
info->append_read_pos=info->write_pos=info->write_buffer;
+ ++info->disk_writes;
UNLOCK_APPEND_BUFFER;
DBUG_RETURN(info->error);
}
diff --git a/mysys/mf_keycache.c b/mysys/mf_keycache.c
index 08737221fb2..689391537f8 100644
--- a/mysys/mf_keycache.c
+++ b/mysys/mf_keycache.c
@@ -627,7 +627,7 @@ writes: %ld r_requests: %ld reads: %ld",
a pointer to the last element.
*/
-static inline void link_into_queue(KEYCACHE_WQUEUE *wqueue,
+static void link_into_queue(KEYCACHE_WQUEUE *wqueue,
struct st_my_thread_var *thread)
{
struct st_my_thread_var *last;
@@ -662,7 +662,7 @@ static inline void link_into_queue(KEYCACHE_WQUEUE *wqueue,
See NOTES for link_into_queue
*/
-static inline void unlink_from_queue(KEYCACHE_WQUEUE *wqueue,
+static void unlink_from_queue(KEYCACHE_WQUEUE *wqueue,
struct st_my_thread_var *thread)
{
KEYCACHE_DBUG_PRINT("unlink_from_queue", ("thread %ld", thread->id));
@@ -1961,7 +1961,7 @@ int key_cache_write(KEY_CACHE *keycache,
else if (! (block->status & BLOCK_CHANGED))
link_to_changed_list(keycache, block);
- set_if_smaller(block->offset, offset)
+ set_if_smaller(block->offset, offset);
set_if_bigger(block->length, read_length+offset);
if (! (block->status & BLOCK_ERROR))
diff --git a/mysys/mf_pack.c b/mysys/mf_pack.c
index 638bbaf7baf..2d0a5ea282b 100644
--- a/mysys/mf_pack.c
+++ b/mysys/mf_pack.c
@@ -347,11 +347,25 @@ static my_string NEAR_F expand_tilde(my_string *path)
return (my_string) 0;
}
- /* fix filename so it can be used by open, create .. */
- /* to may be == from */
- /* Returns to */
-my_string unpack_filename(my_string to, const char *from)
+/*
+ Fix filename so it can be used by open, create
+
+ SYNOPSIS
+ unpack_filename()
+ to Store result here. Must be at least of size FN_REFLEN.
+ from Filename in unix format (with ~)
+
+ RETURN
+ # length of to
+
+ NOTES
+ to may be == from
+ ~ will only be expanded if total length < FN_REFLEN
+*/
+
+
+uint unpack_filename(my_string to, const char *from)
{
uint length,n_length;
char buff[FN_REFLEN];
@@ -362,17 +376,17 @@ my_string unpack_filename(my_string to, const char *from)
if (n_length+strlen(from+length) < FN_REFLEN)
{
(void) strmov(buff+n_length,from+length);
- (void) system_filename(to,buff); /* Fix to usably filename */
+ length= system_filename(to,buff); /* Fix to usably filename */
}
else
- (void) system_filename(to,from); /* Fix to usably filename */
- DBUG_RETURN(to);
+ length= system_filename(to,from); /* Fix to usably filename */
+ DBUG_RETURN(length);
} /* unpack_filename */
/* Convert filename (unix standard) to system standard */
/* Used before system command's like open(), create() .. */
- /* Returns to */
+ /* Returns length of to */
uint system_filename(my_string to, const char *from)
{
diff --git a/mysys/mf_soundex.c b/mysys/mf_soundex.c
index 459e304dfd7..75d9270c5af 100644
--- a/mysys/mf_soundex.c
+++ b/mysys/mf_soundex.c
@@ -28,6 +28,10 @@
* *
* As an extension if remove_garbage is set then all non- *
* alpha characters are skipped *
+* *
+* Note, that this implementation corresponds to the *
+* original version of the algorithm, not to the more *
+* popular "enhanced" version, described by Knuth. *
****************************************************************/
#include "mysys_priv.h"
diff --git a/mysys/mf_tempdir.c b/mysys/mf_tempdir.c
index 1ae034af67d..4d244aa7d74 100644
--- a/mysys/mf_tempdir.c
+++ b/mysys/mf_tempdir.c
@@ -17,7 +17,7 @@
#include "mysys_priv.h"
#include <m_string.h>
-#if defined( __WIN__) || defined(OS2)
+#if defined( __WIN__) || defined(OS2) || defined(__NETWARE__)
#define DELIM ';'
#else
#define DELIM ':'
@@ -35,7 +35,7 @@ my_bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist)
{
/* Get default temporary directory */
pathlist=getenv("TMPDIR"); /* Use this if possible */
-#if defined( __WIN__) || defined(OS2)
+#if defined( __WIN__) || defined(OS2) || defined(__NETWARE__)
if (!pathlist)
pathlist=getenv("TEMP");
if (!pathlist)
diff --git a/mysys/mf_tempfile.c b/mysys/mf_tempfile.c
index cca80dcd552..14b8fdc430c 100644
--- a/mysys/mf_tempfile.c
+++ b/mysys/mf_tempfile.c
@@ -123,12 +123,13 @@ File create_temp_file(char *to, const char *dir, const char *prefix,
}
#ifdef OS2
/* changing environ variable doesn't work with VACPP */
- char buffer[256];
- sprintf( buffer, "TMP=%s", dir);
+ char buffer[256], *end;
+ buffer[sizeof[buffer)-1]= 0;
+ end= strxnmov(buffer, sizeof(buffer)-1, (char*) "TMP=", dir, NullS);
/* remove ending backslash */
- if (buffer[strlen(buffer)-1] == '\\')
- buffer[strlen(buffer)-1] = '\0';
- putenv( buffer);
+ if (end[-1] == '\\')
+ end[-1]= 0;
+ putenv(buffer);
#elif !defined(__NETWARE__)
old_env= (char**) environ;
if (dir)
@@ -138,7 +139,7 @@ File create_temp_file(char *to, const char *dir, const char *prefix,
}
#endif
if ((res=tempnam((char*) dir, (char*) prefix)))
- {
+ {
strmake(to,res,FN_REFLEN-1);
(*free)(res);
file=my_create(to,0,
diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c
index abd51369f95..34a03391bc4 100644
--- a/mysys/my_alloc.c
+++ b/mysys/my_alloc.c
@@ -50,6 +50,72 @@ void init_alloc_root(MEM_ROOT *mem_root, uint block_size,
DBUG_VOID_RETURN;
}
+/*
+ SYNOPSIS
+ reset_root_defaults()
+ mem_root memory root to change defaults of
+ block_size new value of block size. Must be
+ greater than ~68 bytes (the exact value depends on
+ platform and compilation flags)
+ pre_alloc_size new size of preallocated block. If not zero,
+ must be equal to or greater than block size,
+ otherwise means 'no prealloc'.
+ DESCRIPTION
+ Function aligns and assigns new value to block size; then it tries to
+ reuse one of existing blocks as prealloc block, or malloc new one of
+ requested size. If no blocks can be reused, all unused blocks are freed
+ before allocation.
+ */
+
+void reset_root_defaults(MEM_ROOT *mem_root, uint block_size,
+ uint pre_alloc_size __attribute__((unused)))
+{
+ mem_root->block_size= block_size-MALLOC_OVERHEAD-sizeof(USED_MEM)-8;
+#if !(defined(HAVE_purify) && defined(EXTRA_DEBUG))
+ if (pre_alloc_size)
+ {
+ uint size= pre_alloc_size + ALIGN_SIZE(sizeof(USED_MEM));
+ if (!mem_root->pre_alloc || mem_root->pre_alloc->size != size)
+ {
+ USED_MEM *mem, **prev= &mem_root->free;
+ /*
+ Free unused blocks, so that consequent calls
+ to reset_root_defaults won't eat away memory.
+ */
+ while (*prev)
+ {
+ mem= *prev;
+ if (mem->size == size)
+ {
+ /* We found a suitable block, no need to do anything else */
+ mem_root->pre_alloc= mem;
+ return;
+ }
+ if (mem->left + ALIGN_SIZE(sizeof(USED_MEM)) == mem->size)
+ {
+ /* remove block from the list and free it */
+ *prev= mem->next;
+ my_free((gptr) mem, MYF(0));
+ }
+ else
+ prev= &mem->next;
+ }
+ /* Allocate new prealloc block and add it to the end of free list */
+ if ((mem= (USED_MEM *) my_malloc(size, MYF(0))))
+ {
+ mem->size= size;
+ mem->left= pre_alloc_size;
+ mem->next= *prev;
+ *prev= mem_root->pre_alloc= mem;
+ }
+ }
+ }
+ else
+#endif
+ mem_root->pre_alloc= 0;
+}
+
+
gptr alloc_root(MEM_ROOT *mem_root,unsigned int Size)
{
#if defined(HAVE_purify) && defined(EXTRA_DEBUG)
diff --git a/mysys/my_div.c b/mysys/my_div.c
index 777ffe403d7..9141ff4fcc5 100644
--- a/mysys/my_div.c
+++ b/mysys/my_div.c
@@ -27,7 +27,7 @@
my_string my_filename(File fd)
{
DBUG_ENTER("my_filename");
- if (fd >= MY_NFILE)
+ if ((uint) fd >= (uint) my_file_limit)
DBUG_RETURN((char*) "UNKNOWN");
if (fd >= 0 && my_file_info[fd].type != UNOPEN)
{
diff --git a/mysys/my_dup.c b/mysys/my_dup.c
index df298780e3e..4b7434e29ea 100644
--- a/mysys/my_dup.c
+++ b/mysys/my_dup.c
@@ -32,7 +32,7 @@ File my_dup(File file, myf MyFlags)
DBUG_ENTER("my_dup");
DBUG_PRINT("my",("file: %d MyFlags: %d", MyFlags));
fd = dup(file);
- filename= (((int) file < MY_NFILE) ?
+ filename= (((uint) file < my_file_limit) ?
my_file_info[(int) file].name : "Unknown");
DBUG_RETURN(my_register_filename(fd, filename, FILE_BY_DUP,
EE_FILENOTFOUND, MyFlags));
diff --git a/mysys/my_file.c b/mysys/my_file.c
new file mode 100644
index 00000000000..6a9d39cf944
--- /dev/null
+++ b/mysys/my_file.c
@@ -0,0 +1,147 @@
+/* Copyright (C) 2000 MySQL 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#include "mysys_priv.h"
+#include "my_static.h"
+#include <m_string.h>
+
+/*
+ set how many open files we want to be able to handle
+
+ SYNOPSIS
+ set_maximum_open_files()
+ max_file_limit Files to open
+
+ NOTES
+ The request may not fulfilled becasue of system limitations
+
+ RETURN
+ Files available to open.
+ May be more or less than max_file_limit!
+*/
+
+#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE) && !defined(HAVE_mit_thread)
+
+#ifndef RLIM_INFINITY
+#define RLIM_INFINITY ((uint) 0xffffffff)
+#endif
+
+static uint set_max_open_files(uint max_file_limit)
+{
+ struct rlimit rlimit;
+ uint old_cur;
+ DBUG_ENTER("set_max_open_files");
+ DBUG_PRINT("enter",("files: %u", max_file_limit));
+
+ if (!getrlimit(RLIMIT_NOFILE,&rlimit))
+ {
+ old_cur= (uint) rlimit.rlim_cur;
+ DBUG_PRINT("info", ("rlim_cur: %u rlim_max: %u",
+ (uint) rlimit.rlim_cur,
+ (uint) rlimit.rlim_max));
+ if (rlimit.rlim_cur == RLIM_INFINITY)
+ rlimit.rlim_cur = max_file_limit;
+ if (rlimit.rlim_cur >= max_file_limit)
+ DBUG_RETURN(rlimit.rlim_cur); /* purecov: inspected */
+ rlimit.rlim_cur= rlimit.rlim_max= max_file_limit;
+ if (setrlimit(RLIMIT_NOFILE, &rlimit))
+ max_file_limit= old_cur; /* Use original value */
+ else
+ {
+ rlimit.rlim_cur= 0; /* Safety if next call fails */
+ (void) getrlimit(RLIMIT_NOFILE,&rlimit);
+ DBUG_PRINT("info", ("rlim_cur: %u", (uint) rlimit.rlim_cur));
+ if (rlimit.rlim_cur) /* If call didn't fail */
+ max_file_limit= (uint) rlimit.rlim_cur;
+ }
+ }
+ DBUG_PRINT("exit",("max_file_limit: %u", max_file_limit));
+ DBUG_RETURN(max_file_limit);
+}
+
+#elif defined (OS2)
+
+static uint set_max_open_files(uint max_file_limit)
+{
+ LONG cbReqCount;
+ ULONG cbCurMaxFH0;
+ APIRET ulrc;
+ DBUG_ENTER("set_max_open_files");
+
+ /* get current limit */
+ cbReqCount = 0;
+ DosSetRelMaxFH( &cbReqCount, &cbCurMaxFH0);
+
+ /* set new limit */
+ if ((cbReqCount = max_file_limit - cbCurMaxFH0) > 0)
+ ulrc = DosSetRelMaxFH( &cbReqCount, &cbCurMaxFH);
+ DBUG_RETURN(cbCurMaxFH0);
+}
+
+#else
+static int set_max_open_files(uint max_file_limit)
+{
+ /* We don't know the limit. Return best guess */
+ return min(max_file_limit, OS_FILE_LIMIT);
+}
+#endif
+
+
+/*
+ Change number of open files
+
+ SYNOPSIS:
+ my_set_max_open_files()
+ files Number of requested files
+
+ RETURN
+ number of files available for open
+*/
+
+uint my_set_max_open_files(uint files)
+{
+ struct st_my_file_info *tmp;
+ DBUG_ENTER("my_set_max_open_files");
+ DBUG_PRINT("enter",("files: %u my_file_limit: %u", files, my_file_limit));
+
+ files= set_max_open_files(min(files, OS_FILE_LIMIT));
+ if (files <= MY_NFILE)
+ DBUG_RETURN(files);
+
+ if (!(tmp= (struct st_my_file_info*) my_malloc(sizeof(*tmp) * files,
+ MYF(MY_WME))))
+ DBUG_RETURN(MY_NFILE);
+
+ /* Copy any initialized files */
+ memcpy((char*) tmp, (char*) my_file_info, sizeof(*tmp) * my_file_limit);
+ my_free_open_file_info(); /* Free if already allocated */
+ my_file_info= tmp;
+ my_file_limit= files;
+ DBUG_PRINT("exit",("files: %u", files));
+ DBUG_RETURN(files);
+}
+
+
+void my_free_open_file_info()
+{
+ DBUG_ENTER("my_free_file_info");
+ if (my_file_info != my_file_info_default)
+ {
+ my_free((char*) my_file_info, MYF(0));
+ my_file_info= my_file_info_default;
+ }
+ DBUG_VOID_RETURN;
+}
diff --git a/mysys/my_fopen.c b/mysys/my_fopen.c
index d3b0b90f9c5..8906a288b11 100644
--- a/mysys/my_fopen.c
+++ b/mysys/my_fopen.c
@@ -42,7 +42,7 @@ FILE *my_fopen(const char *FileName, int Flags, myf MyFlags)
on some OS (SUNOS). Actually the filename save isn't that important
so we can ignore if this doesn't work.
*/
- if ((uint) fileno(fd) >= MY_NFILE)
+ if ((uint) fileno(fd) >= my_file_limit)
{
thread_safe_increment(my_stream_opened,&THR_LOCK_open);
DBUG_RETURN(fd); /* safeguard */
@@ -91,7 +91,7 @@ int my_fclose(FILE *fd, myf MyFlags)
}
else
my_stream_opened--;
- if ((uint) file < MY_NFILE && my_file_info[file].type != UNOPEN)
+ if ((uint) file < my_file_limit && my_file_info[file].type != UNOPEN)
{
my_file_info[file].type = UNOPEN;
my_free(my_file_info[file].name, MYF(MY_ALLOW_ZERO_PTR));
@@ -123,11 +123,11 @@ FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags)
{
pthread_mutex_lock(&THR_LOCK_open);
my_stream_opened++;
- if (Filedes < MY_NFILE)
+ if ((uint) Filedes < (uint) my_file_limit)
{
if (my_file_info[Filedes].type != UNOPEN)
{
- my_file_opened--; /* File is opened with my_open ! */
+ my_file_opened--; /* File is opened with my_open ! */
}
else
{
diff --git a/mysys/my_gethwaddr.c b/mysys/my_gethwaddr.c
new file mode 100644
index 00000000000..72f1cb975c4
--- /dev/null
+++ b/mysys/my_gethwaddr.c
@@ -0,0 +1,130 @@
+/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/* get hardware address for an interface */
+/* if there are many available, any non-zero one can be used */
+
+#include "mysys_priv.h"
+#include <m_string.h>
+
+#ifndef MAIN
+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;
+}
+
+#ifdef __FreeBSD__
+
+#include <net/ethernet.h>
+#include <sys/sysctl.h>
+#include <net/route.h>
+#include <net/if.h>
+#include <net/if_dl.h>
+
+my_bool my_gethwaddr(uchar *to)
+{
+ size_t len;
+ uchar *buf, *next, *end, *addr;
+ struct if_msghdr *ifm;
+ struct sockaddr_dl *sdl;
+ int i, 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;
+ if (!(buf = alloca(len)))
+ goto err;
+ if (sysctl(mib, 6, buf, &len, NULL, 0) < 0)
+ goto err;
+
+ end = buf + len;
+
+ for (next = buf ; res && next < end ; next += ifm->ifm_msglen)
+ {
+ ifm = (struct if_msghdr *)next;
+ if (ifm->ifm_type == RTM_IFINFO)
+ {
+ sdl = (struct sockaddr_dl *)(ifm + 1);
+ addr=LLADDR(sdl);
+ res=memcpy_and_test(to, addr, ETHER_ADDR_LEN);
+ }
+ }
+
+err:
+ return res;
+}
+
+#elif __linux__
+
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <net/ethernet.h>
+
+my_bool my_gethwaddr(uchar *to)
+{
+ int fd, res=1;
+ struct ifreq 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, SIOCGIFHWADDR, &ifr) >= 0)
+ res=memcpy_and_test(to, (uchar *)&ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
+ } while (res && (errno == 0 || errno == ENODEV) && ifr.ifr_name[3]++ < '6');
+
+ close(fd);
+err:
+ return res;
+}
+
+#else
+/* just fail */
+my_bool my_gethwaddr(uchar *to __attribute__((unused)))
+{
+ return 1;
+}
+#endif
+
+#else MAIN
+int main(int argc __attribute__((unused)),char **argv)
+{
+ uchar mac[6];
+ uint i;
+ MY_INIT(argv[0]);
+ if (my_gethwaddr(mac))
+ {
+ printf("my_gethwaddr failed with errno %d\n", errno);
+ exit(1);
+ }
+ for (i=0; i < sizeof(mac); i++)
+ {
+ if (i) printf(":");
+ printf("%02x", mac[i]);
+ }
+ printf("\n");
+ return 0;
+}
+#endif
+
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c
index b278eaa36e1..8a1f6db6f8a 100644
--- a/mysys/my_getopt.c
+++ b/mysys/my_getopt.c
@@ -324,9 +324,11 @@ int handle_options(int *argc, char ***argv,
--enable-'option-name'.
*optend was set to '0' if one used --disable-option
*/
- *((my_bool*) value)= (my_bool) (!optend || *optend == '1');
- (*argc)--;
- get_one_option(optp->id, optp, argument);
+ my_bool tmp= (my_bool) (!optend || *optend == '1');
+ *((my_bool*) value)= tmp;
+ (*argc)--;
+ get_one_option(optp->id, optp,
+ tmp ? (char*) "1" : disabled_my_option);
continue;
}
argument= optend;
@@ -655,18 +657,15 @@ static longlong eval_num_suffix (char *argument, int *error, char *option_name)
static longlong getopt_ll(char *arg, const struct my_option *optp, int *err)
{
longlong num;
+ ulonglong block_size= (optp->block_size ? (ulonglong) optp->block_size : 1L);
num= eval_num_suffix(arg, err, (char*) optp->name);
- if (num < (longlong) optp->min_value)
- num= (longlong) optp->min_value;
- else if (num > 0 && (ulonglong) num > (ulonglong) (ulong) optp->max_value
- && optp->max_value) /* if max value is not set -> no upper limit */
+ if (num > 0 && (ulonglong) num > (ulonglong) (ulong) optp->max_value &&
+ optp->max_value) /* if max value is not set -> no upper limit */
num= (longlong) (ulong) optp->max_value;
- num= ((num - (longlong) optp->sub_size) / (optp->block_size ?
- (ulonglong) optp->block_size :
- 1L));
- return (longlong) (num * (optp->block_size ? (ulonglong) optp->block_size :
- 1L));
+ num= ((num - (longlong) optp->sub_size) / block_size);
+ num= (longlong) (num * block_size);
+ return max(num, optp->min_value);
}
/*
diff --git a/mysys/my_getsystime.c b/mysys/my_getsystime.c
new file mode 100644
index 00000000000..bdaa232d560
--- /dev/null
+++ b/mysys/my_getsystime.c
@@ -0,0 +1,48 @@
+/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/* get time since epoc in 100 nanosec units */
+/* thus to get the current time we should use the system function
+ with the highest possible resolution */
+
+#ifdef __NETWARE__
+#include <nks/time.h>
+#endif
+
+#include "mysys_priv.h"
+ulonglong my_getsystime()
+{
+#ifdef HAVE_CLOCK_GETTIME
+ struct timespec tp;
+ clock_gettime(CLOCK_REALTIME, &tp);
+ return (ulonglong)tp.tv_sec*10000000+(ulonglong)tp.tv_nsec/100;
+#elif defined(__WIN__)
+ /* TODO: use GetSystemTimeAsFileTime here or
+ QueryPerformanceCounter/QueryPerformanceFrequency */
+ struct _timeb tb;
+ _ftime(&tb);
+ return (ulonglong)tb.time*10000000+(ulonglong)tb.millitm*10000;
+#elif defined(__NETWARE__)
+ NXTime_t tm;
+ NXGetTime(NX_SINCE_1970, NX_NSECONDS, &tm);
+ return (ulonglong)tm/100;
+#else
+ /* TODO: check for other possibilities for hi-res timestamping */
+ struct timeval tv;
+ gettimeofday(&tv,NULL);
+ return (ulonglong)tv.tv_sec*10000000+(ulonglong)tv.tv_usec*10;
+#endif
+}
diff --git a/mysys/my_handler.c b/mysys/my_handler.c
index 6ee6167d3c1..35f620ccbcb 100644
--- a/mysys/my_handler.c
+++ b/mysys/my_handler.c
@@ -9,7 +9,7 @@
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
-
+
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
@@ -18,15 +18,21 @@
#include "my_handler.h"
int mi_compare_text(CHARSET_INFO *charset_info, uchar *a, uint a_length,
- uchar *b, uint b_length, my_bool part_key)
+ uchar *b, uint b_length, my_bool part_key,
+ my_bool skip_end_space)
{
if (part_key && b_length < a_length)
a_length=b_length;
- return my_strnncoll(charset_info, a, a_length, b, b_length);
+ if (skip_end_space)
+ return charset_info->coll->strnncollsp(charset_info, a, a_length,
+ b, b_length);
+ return charset_info->coll->strnncoll(charset_info, a, a_length,
+ b, b_length);
}
+
static int compare_bin(uchar *a, uint a_length, uchar *b, uint b_length,
- my_bool part_key)
+ my_bool part_key, my_bool skip_end_space)
{
uint length= min(a_length,b_length);
uchar *end= a+ length;
@@ -37,6 +43,31 @@ static int compare_bin(uchar *a, uint a_length, uchar *b, uint b_length,
return flag;
if (part_key && b_length < a_length)
return 0;
+ if (skip_end_space && a_length != b_length)
+ {
+ int swap= 0;
+ /*
+ We are using space compression. We have to check if longer key
+ has next character < ' ', in which case it's less than the shorter
+ key that has an implicite space afterwards.
+
+ This code is identical to the one in
+ strings/ctype-simple.c:my_strnncollsp_simple
+ */
+ if (a_length < b_length)
+ {
+ /* put shorter key in a */
+ a_length= b_length;
+ a= b;
+ swap= -1; /* swap sign of result */
+ }
+ for (end= a + a_length-length; a < end ; a++)
+ {
+ if (*a != ' ')
+ return ((int) *a - (int) ' ') ^ swap;
+ }
+ return 0;
+ }
return (int) (a_length-b_length);
}
@@ -128,7 +159,8 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a,
if (piks &&
(flag=mi_compare_text(keyseg->charset,a,a_length,b,b_length,
(my_bool) ((nextflag & SEARCH_PREFIX) &&
- next_key_length <= 0))))
+ next_key_length <= 0),
+ !(nextflag & SEARCH_PREFIX))))
return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag);
a+=a_length;
b+=b_length;
@@ -137,17 +169,11 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a,
else
{
uint length=(uint) (end-a), a_length=length, b_length=length;
- if (!(nextflag & SEARCH_PREFIX))
- {
- while (a_length && a[a_length-1] == ' ')
- a_length--;
- while (b_length && b[b_length-1] == ' ')
- b_length--;
- }
if (piks &&
(flag= mi_compare_text(keyseg->charset, a, a_length, b, b_length,
(my_bool) ((nextflag & SEARCH_PREFIX) &&
- next_key_length <= 0))))
+ next_key_length <= 0),
+ !(nextflag & SEARCH_PREFIX))))
return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag);
a=end;
b+=length;
@@ -164,7 +190,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a,
if (piks &&
(flag=compare_bin(a,a_length,b,b_length,
(my_bool) ((nextflag & SEARCH_PREFIX) &&
- next_key_length <= 0))))
+ next_key_length <= 0),1)))
return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag);
a+=a_length;
b+=b_length;
@@ -176,7 +202,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a,
if (piks &&
(flag=compare_bin(a,length,b,length,
(my_bool) ((nextflag & SEARCH_PREFIX) &&
- next_key_length <= 0))))
+ next_key_length <= 0),0)))
return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag);
a+=length;
b+=length;
@@ -184,26 +210,23 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a,
break;
case HA_KEYTYPE_VARTEXT:
{
- int a_length,b_length,pack_length;
+ int a_length,full_a_length,b_length,full_b_length,pack_length;
get_key_length(a_length,a);
get_key_pack_length(b_length,pack_length,b);
+ full_a_length= a_length;
+ full_b_length= b_length;
next_key_length=key_length-b_length-pack_length;
- if (!(nextflag & (SEARCH_PREFIX | SEARCH_UPDATE)))
- {
- while (a_length && a[a_length-1] == ' ')
- a_length--;
- while (b_length && b[b_length-1] == ' ')
- b_length--;
- }
-
if (piks &&
(flag= mi_compare_text(keyseg->charset,a,a_length,b,b_length,
(my_bool) ((nextflag & SEARCH_PREFIX) &&
- next_key_length <= 0))))
+ next_key_length <= 0),
+ (my_bool) ((nextflag & (SEARCH_FIND |
+ SEARCH_UPDATE)) ==
+ SEARCH_FIND))))
return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag);
- a+=a_length;
- b+=b_length;
+ a+= full_a_length;
+ b+= full_b_length;
break;
}
break;
@@ -217,7 +240,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a,
if (piks &&
(flag=compare_bin(a,a_length,b,b_length,
(my_bool) ((nextflag & SEARCH_PREFIX) &&
- next_key_length <= 0))))
+ next_key_length <= 0), 0)))
return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag);
a+=a_length;
b+=b_length;
@@ -308,7 +331,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a,
if (keyseg->flag & HA_REVERSE_SORT)
{
- swap(uchar*,a,b);
+ swap(uchar*,a,b);
swap_flag=1; /* Remember swap of a & b */
end= a+ (int) (end-b);
}
diff --git a/mysys/my_init.c b/mysys/my_init.c
index d68af1400c5..fc178b0308b 100644
--- a/mysys/my_init.c
+++ b/mysys/my_init.c
@@ -19,10 +19,6 @@
#include "mysys_err.h"
#include <m_string.h>
#include <m_ctype.h>
-#ifdef HAVE_GETRUSAGE
-#include <sys/resource.h>
-/* extern int getrusage(int, struct rusage *); */
-#endif
#include <signal.h>
#ifdef VMS
#include <my_static.c>
@@ -242,8 +238,13 @@ static void my_win_init(void)
setlocale(LC_CTYPE, ""); /* To get right sortorder */
- /* Clear the OS system variable TZ and avoid the 100% CPU usage */
+#if defined(_MSC_VER) && (_MSC_VER < 1300)
+ /*
+ Clear the OS system variable TZ and avoid the 100% CPU usage
+ Only for old versions of Visual C++
+ */
_putenv( "TZ=" );
+#endif
_tzset();
/* apre la chiave HKEY_LOCAL_MACHINES\software\MySQL */
diff --git a/mysys/my_new.cc b/mysys/my_new.cc
index ec27502d8aa..14423c3afd5 100644
--- a/mysys/my_new.cc
+++ b/mysys/my_new.cc
@@ -19,10 +19,10 @@
with gcc 3.0.x to avoid including libstdc++
*/
-#ifdef USE_MYSYS_NEW
-
#include "mysys_priv.h"
+#ifdef USE_MYSYS_NEW
+
void *operator new (size_t sz)
{
return (void *) malloc (sz ? sz : 1);
diff --git a/mysys/my_open.c b/mysys/my_open.c
index 97f21724e1c..ca5c0d8683f 100644
--- a/mysys/my_open.c
+++ b/mysys/my_open.c
@@ -86,7 +86,7 @@ int my_close(File fd, myf MyFlags)
if (MyFlags & (MY_FAE | MY_WME))
my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG),my_filename(fd),errno);
}
- if ((uint) fd < MY_NFILE && my_file_info[fd].type != UNOPEN)
+ if ((uint) fd < my_file_limit && my_file_info[fd].type != UNOPEN)
{
my_free(my_file_info[fd].name, MYF(0));
#if defined(THREAD) && !defined(HAVE_PREAD)
@@ -115,7 +115,7 @@ File my_register_filename(File fd, const char *FileName, enum file_type
{
if ((int) fd >= 0)
{
- if ((int) fd >= MY_NFILE)
+ if ((uint) fd >= my_file_limit)
{
#if defined(THREAD) && !defined(HAVE_PREAD)
(void) my_close(fd,MyFlags);
diff --git a/mysys/my_static.c b/mysys/my_static.c
index b24ef28b7b1..5f034555156 100644
--- a/mysys/my_static.c
+++ b/mysys/my_static.c
@@ -34,7 +34,9 @@ int NEAR my_umask=0664, NEAR my_umask_dir=0777;
#ifndef THREAD
int NEAR my_errno=0;
#endif
-struct my_file_info my_file_info[MY_NFILE]= {{0,UNOPEN}};
+struct st_my_file_info my_file_info_default[MY_NFILE]= {{0,UNOPEN}};
+uint my_file_limit= MY_NFILE;
+struct st_my_file_info *my_file_info= my_file_info_default;
/* From mf_brkhant */
int NEAR my_dont_interrupt=0;
diff --git a/mysys/my_static.h b/mysys/my_static.h
index 08d1a93692f..bb408aa808d 100644
--- a/mysys/my_static.h
+++ b/mysys/my_static.h
@@ -68,6 +68,8 @@ extern byte *sf_min_adress,*sf_max_adress;
extern uint sf_malloc_count;
extern struct st_irem *sf_malloc_root;
+extern struct st_my_file_info my_file_info_default[MY_NFILE];
+
#if defined(THREAD) && !defined(__WIN__)
extern sigset_t my_signals; /* signals blocked by mf_brkhant */
#endif
diff --git a/mysys/my_tempnam.c b/mysys/my_tempnam.c
index d079b9f66a5..b4f76727ee0 100644
--- a/mysys/my_tempnam.c
+++ b/mysys/my_tempnam.c
@@ -105,12 +105,13 @@ my_string my_tempnam(const char *dir, const char *pfx,
}
#ifdef OS2
/* changing environ variable doesn't work with VACPP */
- char buffer[256];
- sprintf( buffer, "TMP=%s", dir);
+ char buffer[256], *end;
+ buffer[sizeof[buffer)-1]= 0;
+ end= strxnmov(buffer, sizeof(buffer)-1, (char*) "TMP=", dir, NullS);
/* remove ending backslash */
- if (buffer[strlen(buffer)-1] == '\\')
- buffer[strlen(buffer)-1] = '\0';
- putenv( buffer);
+ if (end[-1] == '\\')
+ end[-1]= 0;
+ putenv(buffer);
#elif !defined(__NETWARE__)
old_env=(char**)environ;
if (dir)
diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c
index 237eeefa325..445cef0cd6f 100644
--- a/mysys/my_thr_init.c
+++ b/mysys/my_thr_init.c
@@ -104,7 +104,7 @@ void my_thread_global_end(void)
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
pthread_mutexattr_destroy(&my_fast_mutexattr);
#endif
-#ifdef PPTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
+#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
pthread_mutexattr_destroy(&my_errchk_mutexattr);
#endif
pthread_mutex_destroy(&THR_LOCK_malloc);
diff --git a/mysys/mysys_priv.h b/mysys/mysys_priv.h
index f79431a0b0b..6abadd48aeb 100644
--- a/mysys/mysys_priv.h
+++ b/mysys/mysys_priv.h
@@ -21,6 +21,10 @@
#include "system_wrappers.h"
#endif
+#ifdef HAVE_GETRUSAGE
+#include <sys/resource.h>
+#endif
+
#ifdef THREAD
#include <my_pthread.h>
extern pthread_mutex_t THR_LOCK_malloc, THR_LOCK_open, THR_LOCK_keycache;
@@ -29,3 +33,4 @@ extern pthread_mutex_t THR_LOCK_charset;
#else
#include <my_no_pthread.h>
#endif
+
diff --git a/mysys/test_fn.c b/mysys/test_fn.c
index 5a0546392ab..d0fb9f59fd6 100644
--- a/mysys/test_fn.c
+++ b/mysys/test_fn.c
@@ -59,7 +59,8 @@ int main(int argc __attribute__((unused)), char **argv)
printf("org : '%s'\n",*pos);
printf("pack: '%s'\n",fn_format(buff,*pos,"","",8));
printf("unpack: '%s'\n",fn_format(buff2,*pos,"","",4));
- if (strcmp(unpack_filename(buff,buff),buff2) != 0)
+ unpack_filename(buff,buff);
+ if (strcmp(buff,buff2) != 0)
{
printf("error on cmp: '%s' != '%s'\n",buff,buff2);
}
diff --git a/mysys/tree.c b/mysys/tree.c
index 42c58131100..063c8739e58 100644
--- a/mysys/tree.c
+++ b/mysys/tree.c
@@ -170,8 +170,8 @@ void delete_tree(TREE* tree)
void reset_tree(TREE* tree)
{
+ /* do not free mem_root, just mark blocks as free */
free_tree(tree, MYF(MY_MARK_BLOCKS_FREE));
- /* do not my_free() mem_root if applicable, just mark blocks as free */
}
@@ -188,10 +188,14 @@ static void delete_tree_element(TREE *tree, TREE_ELEMENT *element)
}
}
- /* Code for insert, search and delete of elements */
- /* parent[0] = & parent[-1][0]->left ||
- parent[0] = & parent[-1][0]->right */
+/*
+ insert, search and delete of elements
+
+ The following should be true:
+ parent[0] = & parent[-1][0]->left ||
+ parent[0] = & parent[-1][0]->right
+*/
TREE_ELEMENT *tree_insert(TREE *tree, void *key, uint key_size,
void* custom_arg)
@@ -232,8 +236,7 @@ TREE_ELEMENT *tree_insert(TREE *tree, void *key, uint key_size,
if (tree->with_delete)
element=(TREE_ELEMENT *) my_malloc(alloc_size, MYF(MY_WME));
else
- element=(TREE_ELEMENT *)
- alloc_root(&tree->mem_root,alloc_size);
+ element=(TREE_ELEMENT *) alloc_root(&tree->mem_root,alloc_size);
if (!element)
return(NULL);
**parent=element;
@@ -251,9 +254,9 @@ TREE_ELEMENT *tree_insert(TREE *tree, void *key, uint key_size,
}
else
memcpy((byte*) element+tree->offset_to_key,key,(size_t) key_size);
- element->count=1; /* May give warning in purify */
+ element->count=1; /* May give warning in purify */
tree->elements_in_tree++;
- rb_insert(tree,parent,element); /* rebalance tree */
+ rb_insert(tree,parent,element); /* rebalance tree */
}
else
{
@@ -320,6 +323,8 @@ int tree_delete(TREE *tree, void *key, void *custom_arg)
rb_delete_fixup(tree,parent);
if (tree->free)
(*tree->free)(ELEMENT_KEY(tree,element), free_free, tree->custom_arg);
+ /* This doesn't include key_size, but better than nothing */
+ tree->allocated-= sizeof(TREE_ELEMENT)+tree->size_of_element;
my_free((gptr) element,MYF(0));
tree->elements_in_tree--;
return 0;
@@ -476,7 +481,6 @@ ha_rows tree_record_pos(TREE *tree, const void *key,
TREE_ELEMENT *element= tree->root;
double left= 1;
double right= tree->elements_in_tree;
- ha_rows last_equal_pos= HA_POS_ERROR;
while (element != &tree->null_element)
{
@@ -485,9 +489,6 @@ ha_rows tree_record_pos(TREE *tree, const void *key,
{
switch (flag) {
case HA_READ_KEY_EXACT:
- last_equal_pos= (ha_rows) ((left + right) / 2);
- cmp= 1;
- break;
case HA_READ_BEFORE_KEY:
cmp= 1;
break;
@@ -511,7 +512,6 @@ ha_rows tree_record_pos(TREE *tree, const void *key,
}
switch (flag) {
case HA_READ_KEY_EXACT:
- return last_equal_pos;
case HA_READ_BEFORE_KEY:
return (ha_rows) right;
case HA_READ_AFTER_KEY: