  We obtain a necessary and sufficient condition on an exponent $p(\cdot)$ for
which the Hardy--Littlewood maximal operator is bounded on the variable
$L^{p(\cdot)}$ space. It is formulated in terms of the Muckenhoupt-type
condition $A_{p(\cdot)}$, responsible for a local control of $p(\cdot)$, and a
certain integral condition on $p(\cdot)$, responsible for the behaviour of
$p(\cdot)$ at infinity. Our approach is based on an earlier characterization
established by L. Diening and on non-increasing rearrangements.
