src/hotspot/share/classfile/classListParser.cpp
changeset 47216 71c04702a3d5
parent 34257 4be3504cc03b
child 48138 78b2ecdd3c4b
equal deleted inserted replaced
47215:4ebc2e2fb97c 47216:71c04702a3d5
       
     1 /*
       
     2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  *
       
    23  */
       
    24 
       
    25 #include "precompiled.hpp"
       
    26 #include "classfile/classListParser.hpp"
       
    27 #include "runtime/os.hpp"
       
    28 #include "runtime/java.hpp"
       
    29 
       
    30 ClassListParser::ClassListParser(const char* file) {
       
    31   _classlist_file = file;
       
    32   _file = fopen(file, "r");
       
    33   if (_file == NULL) {
       
    34     char errmsg[JVM_MAXPATHLEN];
       
    35     os::lasterror(errmsg, JVM_MAXPATHLEN);
       
    36     vm_exit_during_initialization("Loading classlist failed", errmsg);
       
    37   }
       
    38 }
       
    39 
       
    40 ClassListParser::~ClassListParser() {
       
    41   if (_file) {
       
    42     fclose(_file);
       
    43   }
       
    44 }
       
    45 
       
    46 bool ClassListParser::parse_one_line() {
       
    47   for (;;) {
       
    48     if (fgets(_line, sizeof(_line), _file) == NULL) {
       
    49       return false;
       
    50     }
       
    51     int line_len = (int)strlen(_line);
       
    52     if (line_len > _max_allowed_line_len) {
       
    53       tty->print_cr("input line too long (must be no longer than %d chars)", _max_allowed_line_len);
       
    54       vm_exit_during_initialization("Loading classlist failed");
       
    55     }
       
    56     if (*_line == '#') { // comment
       
    57       continue;
       
    58     }
       
    59     break;
       
    60   }
       
    61 
       
    62   // Remove trailing \r\n
       
    63   _line[strcspn(_line, "\r\n")] = 0;
       
    64   return true;
       
    65 }
       
    66